I’m looking at somebody’s javascript code that is minimized and I see a syntax that doesn’t make any sense.
firstObject.init = function() {
void 0 === secondObject.properties && thirsObject.reportError("Something is wrong");
firstObject.doSomething();
}
My guess is that packer is checking for an undefined property, breaking out of the execution context and returning null in that case.
if (secondObject.properties === undefined) {
thirdObject.reportError("Something is wrong");
return NULL;
}
What’s going on here?
If you look at the result of
void 0it quickly becomes clear what’s happening:Therefore, writing
is simply a different way of writing
Condition evaluation is usually
lazy“short-circuit”, that is, if it is already certain that a condition will evaluate to true or false, further sub-conditions are not evaluated anymore. For example:If you have any two conditions combined by a
&&operator, if the first (left) condition is false, the entire condition will be false no matter the it’s value. Therefore, evaluation of the second condition is not necessary, and thus discarded.More information:
Lazy evaluation on Wikipedia