JavaScript is a loosely typed language. This means types can be changed at any time.
This means that when you need to do comparisons you need to be careful when choosing between strict equality (`===`) and loose equality (`==`) operators.
Strict equality
Using `===` is a strict equality comparison. This means that neither value is converted prior to the comparison. This further means that the value and type has to match in order for the statement to be true.
Loose equality
Using `==` is a loose or abstract equality comparison. The types are converted prior to the comparison. Types doesn’t matter as long as the values are the same.
13 === "13" // FALSE (Strict equality comparison)13 == "13" // TRUE (Loose/Abstract equality comparison)
When to use which
In most circumstances you should use the strict equality comparison.
However, loose equality comparison can be useful in certain limited scenarios where you want the comparison to be flexible.
For example. you don’t know if a value will be null, false, 0, or undefined but you want to treat all these answers the same. Using the loose equality comparison will allow you to check for ‘falsey’ values rather than false values.
For more information see the MDN documentation on Equality and Sameness