I recently came across the site wtfjs.com. It highlights some idiosyncrasies of the Javascript language. It’s worth a look, you’ll get a deeper understanding of the Javascript language.
This entry submitted by @diogobaeder held my attention. The solution was not immediately obvious to me so I did some digging. Once I found the correct type coercion rules the result were logical.
1 2 3 |
|
These examine this step by step.
1
|
|
The above was obvious. References to the same object evaluate to true.
1
|
|
The expression above took a little longer to decipher.
First the precedence rules come into play.
1 2 |
|
If either operand is a number or a boolean, the operands are converted to numbers.
1 2 3 4 |
|