Logical operator || in javascript, 0 stands for Boolean false?

|| — expr1 || expr2 (Logical OR) Returns expr1 if it can be converted to true; otherwise, returns expr2. Thus, when used with Boolean values, || returns true if either operand is true; if both are false, returns false.. && — expr1 && expr2 (Logical AND) Returns expr1 if it can be converted to false; … Read more

Shortcut “or-assignment” (|=) operator in Java

The |= is a compound assignment operator (JLS 15.26.2) for the boolean logical operator | (JLS 15.22.2); not to be confused with the conditional-or || (JLS 15.24). There are also &= and ^= corresponding to the compound assignment version of the boolean logical & and ^ respectively. In other words, for boolean b1, b2, these … Read more

What does “var FOO = FOO || {}” (assign a variable or an empty object to that variable) mean in Javascript?

Your guess as to the intent of || {} is pretty close. This particular pattern when seen at the top of files is used to create a namespace, i.e. a named object under which functions and variables can be created without unduly polluting the global object. The reason why it’s used is so that if … Read more

JavaScript OR (||) variable assignment explanation

Javacript uses short-circuit evaluation for logical operators || and &&. However, it’s different to other languages in that it returns the result of the last value that halted the execution, instead of a true, or false value. The following values are considered falsy in JavaScript. false null “” (empty string) 0 Nan undefined Ignoring the … Read more