This post expects prior knowledge on data types.
Using Triple Equals tests for strict equality, meaning, both the type and the value have to be the same.
Here are some examples that return true:
10 === 10
// true : both Integers and values match
true === true
// true : both Booleans and values match
'hello world' === 'hello world'
// true : both Strings and values match
Here are some examples that return false:
100 === '100'
// false : comparison of an Integer and a String
'red' === 'blue'
// false : both Strings with different values
false === 0
// false : both different types and different value
What if we wanted to test loose equality where only the value mattered? Then we can use
100 == '100'
// true : comparison of an Integer and a String
false == 0
The example of
false == 0 can be confusing. This example returns
When testing equality using Triple Equals is preferred. Testing the type and value ensure true equality testing.
Both experience and this article provided information on the topic and describes in detail what falsy means.