Answer the question
In order to leave comments, you need to log in
Why is 0 equal to both true and false?
Hello.
I'm studying JS, and I was wondering:
Why when we compare the number 0 and false: it displays true, and when we apply the strict comparison
operator : it
displays false.
Why is that?
It seems like 0 = false, and when comparing with a strict comparison operator, it should be true, as well as when comparing with a regular comparison operator.
console.log(0 == false);
console.log(0 === false);
Answer the question
In order to leave comments, you need to log in
The strict assignment operator also checks that both values have the same type.
typeof(true) -> "boolean"
typeof(0) -> "number"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question