which assigns the value of xin name argument if it is not false (or undefined or null) or a new object ( {} );
example:
var name = xin || {};
this translates to:
if(xin) var name = xin; else name = {};
In javascript, you can use conditional statements ( || and && ) to create expressions. Here is an example:
typeof f === 'function' && ((arguments.length == 0 && f()) || f.apply({},arguments)) || g();
this expression can be translated into the following:
if(typeof f === 'function') { if(arguments.length == 0) f(); else f.apply({},arguments); } else g();
In any case, this is for demonstration purposes only, you should not use large nested expressions built with conditional operators, because they are very unreadable (therefore it is very difficult to maintain).
This type of expression is often used during initialization when you do not want to overwrite a specific value if it already exists. A good example is using a namespace in multiple js files. Using this method ( var namespace = namespace || {}; ), you can use the same namespace in all files without overwriting it.
source share