This is an interesting list of things that you may want to be aware of as you write code as a JavaScript developer.
Most of my difficulty with this language has involved == and if evaluation in server-side javascript when values may or may not be set. If you’re being clever with logic expressions, it may be tempting to convert A || B || C to FALSE if none are true, but really it’s the last entry in the list (C). Think of the last value as an “ELSE” clause.
In any case, consider using === whenever possible to reduce ambiguity.
== vs ===
Logic Expression Weirdness
It’s important to remember that logic expressions like these are not actually booleans. In an OR expression, the first not-evaluated-to-false expression is returned. IF THERE ARE NONE - IT RETURNS THE LAST ENTRY REGARDLESS. It is easy to screw yourself here.
If evaluation
If succeeds if the expression evaluates to any string other than “”, true, or 1.
If fails if the expression evalutes to anything other than the above.
As I run across more, I’ll keep adding them to this list.
The moral of this story is to not use ==. Please use ===.
Also, some will write if(true==condition) for readability in lieu of if(condition). If you do this in conjunction with ==, and especially if others work on the same codebase, expect to be screwed repeatedly.