Double Equals(==)/ Falsy

Keesha Hargrove
2 min readNov 25, 2021

In JavaScript, if we use double equals, we test for loose equality. Type comparison is also performed when using double equals.

When attempting to convert two values into a common type, type coercion is performed.

Let’s look at an example. If we remembered our earlier test:

100 === '100'
// false (Number v. String)

Because of their different types, “100” doesn’t have to mean “100”. If they were tested on a loose equality, then it might be…

100 == '100'
// true

You can see we get true. Coercion is the reason. In reality, JavaScript converts the values as such. Here, the conversion is successful. If you convert '100' to a number, then 100 is the result. The answer is indeed true since 100 equals 100.

Let’s take another example.

Remember how we verified if false equals 0 with strict equality earlier:

false === 0
// false (Different type and value)

This is clearly untrue. If we run the same equation with loose equality, however…

false == 0
// true

We get “true” ? Why…? It has to do with falsy values in JavaScript. We’ll explore this concept in the next section.

This is demonstrably false. However, if we run the same equation with loose equality.

Falsy Values

Is it possible that false equals 0 in JavaScript? 0 in JavaScript is an invalid value, so it is complicated.

Zero will actually become a false boolean through type coercion, and false will then be equal to false.

There are only 6 falsy values in JavaScript :

  • 0 — number zero
  • “” — empty string
  • false — boolean false
  • NaN — Not A Number
  • undefined
  • null

--

--