What is the strict equality operator?
The strict equality operator is used to compare two values to determine if they are equal in both value and data type. It returns true if the values are equal and of the same data type, otherwise it returns false.
How does it work?
This means that a number will never be equal to a string when using the strict equality operator.
Let’s take a look at some examples to better understand how the strict equality operator works:
Example 1: Numbers
10 === 10: Returns true, since both values are numbers and equal.
10 === '10': Returns false, since one value is a number and the other is a string.
10 === 5: Returns false, since both values are numbers but not equal.
Example 2: Strings
'hello' === 'hello': Returns true, since both values are strings and equal.
'hello' === 'world': Returns false, since both values are strings but not equal.
Example 3: Booleans
true === true: Returns true, since both values are booleans and equal.
true === false: Returns false, since both values are booleans but not equal.