A quick shortcut to throw errors for function params

Siddharth - Jun 9 '21 - - Dev Community
function throwError(propName) {
    throw new Error(`'${propName}' is required`)
}

function doSomething(someArg = throwError("someArg")) {
    return someArg;
}

doSomething();
// Uncaught Error: someArg is required
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .