Looking at an online source code I came across this at the top of several source files.
var FOO = FOO || {};
FOO.Bar = …;
But I have no ide
Another common use for || is to set a default value for an undefined function parameter also:
function display(a) {
a = a || 'default'; // here we set the default value of a to be 'default'
console.log(a);
}
// we call display without providing a parameter
display(); // this will log 'default'
display('test'); // this will log 'test' to the console
The equivalent in other programming usually is:
function display(a = 'default') {
// ...
}