The Triple Equals (===)

Keesha Hargrove
1 min readNov 18, 2021

--

JavaScript

As you can see, JavaScript has two ways to test equality visually similar, but they are different. The methods == and === are both visually similar, but they differ substantially. Let’s examine what they are:

===

JavaScript tests for strict equality when using triple equals ===. Therefore, both the type and the value we’re comparing have to match.

I’d like to share a couple examples of strict equality.

The number 8 will be compared to the number 8 in the first example. The result will be true. There is nothing to distinguish them apart other than their values of 8.

8 === 8
// true

The following example will return true when this is taken into account:

'hello world' === 'hello world'
// true (Both Strings, equal values)true === true
// true (Both Booleans, equal values)

In the following examples, we will see what will return false:

The following example compares the number 100 to the string value of 100. Therefore, our operands will have the same value, but be of a different type. Result: False

100 === '100'
// false (Number v. String)

Here are two additional examples:

'car' === 'van'
// false (Both are Strings, but have different values)

To sum up, triple equality (strict equality) is to always compare like types and values.

--

--

No responses yet