Double Equals (==) vs Triple Equals (===) in JavaScript

In JavaScript you might have noticed that you have two ways of making equal comparisons between values:

  • Regular equals: == (double equals)
  • Strict equals: === (triple equals)

The difference between double equals (==) and triple equals (===) is:

  • Regular equals only compare values and ignore value type
  • Strict equals compare both values and value types.

For example:

// returns true
5 == "5"
// returns false
5 === "5"

In the two examples above, the value on the left is a numeric value type, the one the right is a string value type (specified by the quotes ' ').

They both have the value five but one is a numeric value the other is a string value. Strict equals === only evaluates to true if both the value and the value type is the same.

So both of these examples evaluate/return true because their value type on either side of the strict equals is the same:

// returns true
5 === 5
// returns true
"5" === "5"

Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊


Share & Discuss on