In Javascript, 2 || 3
returns 2
. I understand that the OR operator here basically works like 2 ? 2 : 3
, and that this can still work like a boolean in conditionals, like if (2 || 3){...}
evaluates to true. So my current understanding of boolean operators in Javascript is that they do not actually return boolean values, but that they can be used in the same way that booleans can in conditionals, and can yield other useful properties like how a || b
is a shorthand for a ? a : b
. So my questions are:
1) Am I correct in saying "boolean operators in Javascript do not return boolean values"?
2) If so, is the reason they do not return boolean values that they can have other useful properties like the shorthand one above?
Thanks!