JavaScript OR Assignment

12.31.2014

The OR operator takes the leftmost “truthy” value, and if none exists, the last “falsy” value.

var result = 42 || undefined;

result is assigned 42. undefined is never examined because of short-circuit.

var result = 0 || "foo";

result is assigned “foo” because 0 is a falsy value.