1

What the Fun Javascript Part 2

With reference to my old rant : https://devrant.com/rants/1445754/...

An explanation to this...
In JS whenever it sees '==' it has a set of rules that it follows before comparing quantities...

One such rule is...
When we compare a number with a boolean using '==' it first converts boolean into number then compares the two quantities...

So in this case..
When we convert true to number we get 1 and when we compare 1 and 2 they are obviously unequal hence we get false...

Comments
  • 0
    And this, kids, is why we use ===.

    Also this is a feature in most, if not all scripting languages
Add Comment