Q:

Why do some people assigning JavaScript variables like var example = window.example || {};

I been seeing people assigning JavaScript variables such as:
var example = window.example || {};

And I am wondering the reason for this. And yes I am already aware that || is the OR operator and {}; is a object literal.
Would be great if someone could answer, thanks!

A:

Short circuit evaluation exploitation and the fact JavaScript returns the last expression evaluated.
If the LHS is truthy, then the entire expression is satisfied (it's an ||) and JavaScript returns the LHS.
If the LHS is falsy, then the RHS needs to be evaluated, because it is on the other side of the logical or operator (||). Even if the RHS is falsy, it is returned because it is the last expression evaluated.
It is typically used to provide default argument values for functions...
var sayHello = function(name) {
    name = name || 'Alex';
    alert('Hello ' + name);
}

