I am using Google Closure and LOVE conditional assignments. I regularly use the
var stuff = (condition) ? opt0: opt1;
method and have more recently been introduced to
var stuff = opt_param || defaultValue;
But I have noticed a strange behavior, since it seems the
var stuff = opt_param | defaultValue;
is aslso working (i.e. with the single |), but this appears to "type cast" the variable into a number. I have not been able to find any documentation on this, so here's my question:
What is the difference between the single | and the double || in terms of logic and assignment? And is my assumption regarding the number type cast correct, or just an arbitrary product of the special case(s) I've been fiddling with?