say you have an if statement:
try {
if (!a || !b || !c || !d) {
let nullVariable = ???;
// use the variable that is null
throw nullVariable
}
} catch (ex) {
log.debug(`${ex} is not defined`);
}
Is there a built in way to see which variable was set to null, without creating an if statement for each individual variable?
>Solution :
You can put the assignment inside the if condition expression.
let a, b, c, d;
a = 3;
b = "foo";
d = {x: 10};
let nullVariable = (!a && 'a') || (!b && 'b') || (!c && 'c') || (!d && 'd');
if (nullVariable) {
console.log(`${nullVariable} is not defined`);
}