Wednesday, April 4, 2012

javascript || operator gotcha

the OR operator of javascript might not execute the entire condition to complete it.
If it detected that the earlier condition meet, it will automatically abardon the check.

Example:
var x = true;
x = x || runmyfunction();

if x is true, runmyfunction will not be checked or executed. But if x is false, then runmyfunction will be executed to return the value.

No comments: