Unlike other languages, JavaScript has two ways of checking the equality of two values. You can either use double equals (==) or triple equals (===). But how are these two different?
Double Equals (==):
Double equals compares values by converting the values to the same data types. For example:
This code snippet outputs true. Even though value1 and value2 are variables of different data types, the double equal operator treats them as the same data type (or it doesn’t care what their data types are) and only compares the values of these two variables.
Here is another example:
Triple Equals (===):
Unlike double equals, triple equals cares about data types. This means === compares both the data type and the value of two variables. Try this code snippet:
Here, all of the outputs are false because none of the compared values have the same data type, even though they may have the same value.
Conclusion:
Double equals (==) is often referred to as loose equality, while triple equals (===) is referred to as strict equality.