So I found an error in some js code today that I hadn't really expected.
Some background: the javascript logical OR operator ( || ) is pretty awesome. Because js evaluates a bunch of things as false-equivalent, like the empty string, 0, empty array, etc., rather than returning a bool true or false, it returns the last expression evaluated and still keeps the c++ feature of stopping when it hits a false (or false equivalent).
true || false // false
true || 0 // 0
25 || -1 // -1
!true || 0 // false
0 || true // 0
Now, I like to use this to make default values for object properties like this:
options.eval=options.eval || true;
What i forgot however, is that despite this awesome functionality, it's still has the same precedence as the logical OR (makes sense), which is below other operators, like the equality operator for instance.
Took 15 minutes to realize this, and once I did, my code suddenly made sense.
index||0==0 // returns either index or true, so always equates to true in an if statement.
(index||0)==0 // the way it should have been done, to check that index is not defined OR equal to 0