Possible Duplicate:
What does var x = x || {} ;
I have this lines in js, it is simple i am sure but i am not sure what the last part does – (xin || {})
var xin = (function (name) {return name;}(xin || {}));
as I understand it, xin is a object constructor so now I can create object of xin. Just not too sure what the xin || {} does. Can someone enlighten me please, thanks
is the same as:
or, in longer form:
EDIT: See linked duplicate question. jAndy puts it nicely:
||is the logicalOR.The expression
should become more obvious then.
If
xhas a falsy value (likenull,undefined,0,""), we assignxan empty object{}, otherwise just keep the current value. The long version of this would look like