Difference Between == and === in Javascript

Difference Between == and === in Javascript

Let's first understand What is == and === in Javascript

The '==' and '===' operators are used to compare if two values are equal

Some Examples of using '==' and '===' operators

Difference between '==' and '==='

  1. The '==' operator is called loose equality operator
  • it compares two values and also does type conversion

  • When comparing two variables the "==" operator tends to transfer data from one type to another.

  1. The '===' operator is called Strict equality operator
  • it will strictly compare the values of both variables and only if they are exactly equal it will return true otherwise it will return false.

  • the condition for this operator it checks whether both the value and type are equal.

    let's see the difference of using '==' and '==='

Example of using '==' and '===' with objects

  • while comparing the objects with '==' and '===' operands it will result in false condition because the reference of the object is different but the properties are same.

conclusion-

  • '' == '' will check the type and if they are not the same it will perform a type conversion and then show the result

  • " === " will check the type, if that matches then will check the value and show the result. if the type is not the same it will result as false.