Checking Equality In Javascript

Next Story

Const, Let, and Var

One of the most common things that come up in programming is checking equality between objects or variables. In javascript there are two ways of checking equality, == and ===.

They are actually very different things. So it’s good to know the difference between them.

== checks that two objects have the same value, but === checks that the two objects have the same value and also the same data type.

Using the wrong one can cause unforeseen errors in your code.

1 == '1' // this equality check will return true
// whereas
1 === '1' // this equality check will return false

It is preferable to use === whenever possible. It will give you a more definite equality check in case of unwanted bugs.

https://www.googletagmanager.com/gtag/js?id=UA-63695651-4