VOOZH about

URL: https://www.geeksforgeeks.org/javascript/equality-comparison-operator-in-javascript/

⇱ Equality(==) Comparison Operator in JavaScript - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Equality(==) Comparison Operator in JavaScript

Last Updated : 6 Feb, 2026

In JavaScript, the Comparison Equality Operator (==) is used to compare the values of two operands. It returns true if the values are equal and false otherwise. This operator is known as loose equality because it performs automatic type conversion before comparison.

  • Performs type conversion when comparing operands of different types.
  • Returns true only when the values are equal after conversion.
  • When comparing objects, it checks only references, not the actual content of the objects.

Syntax: 

a==b

Note: The equality comparison is symmetric in the sense that a==b is the same as b==a.

[Example 1]: We will use the equality operator on the same data types.

  • c, d, e are strings, but comparison differs.
  • Strings made with new String() are objects.
  • c vs d: reference comparison - false.
  • c vs e: type conversion to string value-true.

[Example 2]: We will use the equality operator on different data types.

  • The boolean and string values are converted to numbers then comparison takes place so true is returned in all cases

[Example 3]: We will compare Date with String using the equality operator.

  • When the date object is compared with the string it is first converted to a string so the comparison returns true.
Comment
Article Tags: