Can you add booleans in JS? Is something false
here? What will be logged to the screen?
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Just as in the
previous test, weβre dealing here with type conversion
and loose equality
using the ==
operator.
When JavaScript evaluates the expression true + true
it first converts booleans to numbers, which is 1
for true
and 0
for false
.
When we try to do calculate the value of 2 == true
, the typecast happens again and we arrive at the final condition 2 == 1
.
The result is obviously false, so we go into the else
branch.
To understand how type conversion works with the +
operator and different data types, you can read
this article.
ANSWER: the string everyone is different after all
will be logged to the console.