Why would you use this syntax?
var myVar = myArray.length && myArray || myObject;
instead
var myVar = myArray.length ? myArray : myObject;
Edit: I just thought that if, in the case of syntax, && ||both sides are ||evaluated as false, as you would expect if you myObjectwere undefinedor nullif false would be returned. But this is not so, the values of the objects undefinedor are returned null.
true || true //true
true || false //true
false || true //true
false || false //false
Edit2:
!!(myArray.length ? myArray : myObject);
However, this returns false if myObjectis undefinedornull
source
share