Understanding ‘==’ vs ‘===’ in JavaScript

== and === are comparison operators in JavaScript.

== is the equality operator, which compares the values of operands. For example, both of the following statements evaluate to true:

  • 5 == 5 // evaluates to true
  • 5 == “5” // evaluates to true

=== is the strict equality operator, which compares both the type and value of the operands. For instance:

  • 5 === 5 // evaluates to true
  • 5 === “5” // evaluates to false