watch on aatventure.news

JavaScript in 90 Seconds | Equality

In JavaScript there are many data types. There are strings, numbers, boolean, null, and undefined. It’s important to understand these types before comparing equality.

2020-01-05 13:00:00 - codeSTACKr

There are two ways to compare, or check for equality. We can use the double ==, or triple ===.


Double == checks for abstract equality, which means that it actually tries to convert the type using type coercion.

Triple === checks for strict equality, so the data types must match.


In general it is always best to use strict equality testing with the triple ===. This way you will not run into any false positive issues in your code. As a best practice, if you do need to check equality on different data types, do the conversion yourself first then check for equality.


More Posts