Boolean Values JavaScript
JavaScript as others languages have a value to represent just two states. Much of times is a result from one comparison, for example:
3 > 2
// true
5 >= 7
//false
But you can use it’s own special keyword true and false, for example let’s compare some others values:
true == 1
//true
false == 0
//true
The reason why this is happening is because boolean values are represented with one bit, and if we remember a bit have just two different states, 0 and 1. But we are using the double equal operator, if we use the triple equal we are going to get the right solution, because it disable automatic type conversion.
true === 1
//false
false === 0
//false
Note: There is only one value that is not equal to itself, and that is NaN(“not a number”)
NaN == NaN
// false
NaN === NaN
// false
You can go deep into boolean values here Eloquent JavaScript.