Have a look at the code below:
// mickey is undefined
var mickey;
var spidey = mickey || '5';
// you will see "5"
alert( spidey );
Also, you can use this tip in:
function myFUnc( param )
{
var newParam = param || 'default';
// ...
}
The double pipe is great, don’t you? However, you have to be careful, because this tip can be dangerous. See some example below:
var a = 0; // zero or false can be dangerous
var b = a || '5';
alert( a ); // you will see "5"
var a = false;
var b = a || '5';
alert( b ); // you will see "5"
var a = 1;
var b = a || '5';
alert( b ); // you will see "1"