DEV Community

Ashwin vijay
Ashwin vijay

Posted on

Difference ==(Loose Equality) and ===(Strict Equality)?

==(Loose Equality)

  • Compares value only.
  • Does type coercion if the types are different. eg:console.log(5=='5') it will return true.it will convert the string to number
  • It is converted to number instead of string because number as it is simple eg: console.log(0==false) in this line false boolean type is converted to 0 and finally 0==0 which it will return true.

===(Tight Equality)

  • Compares both value and type
  • It will not do type coercion , eg:console.log(5==='5').it will return false console.log(0==false).will return false.

Top comments (0)