A
A
Anonymous Nonamev2021-06-10 09:03:39
JavaScript
Anonymous Nonamev, 2021-06-10 09:03:39

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

2 answer(s)
V
Vasily Bannikov, 2021-06-10
@vabka

The strict assignment operator also checks that both values ​​have the same type.
typeof(true) -> "boolean"
typeof(0) -> "number"

G
Gary_Ihar, 2021-06-10
@Gary_Ihar

Wow, look: poke

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question