DEV Community

Cover image for '==' vs '===' in JavaScript
Raj Kishor Shaw
Raj Kishor Shaw

Posted on • Originally published at rajkishor.hashnode.dev

'==' vs '===' in JavaScript

As a developer many times, we see other developers using Strict Equality Operator(===) instead of Abstract Equality Operator(==) and wonder if there is really any major difference between the two? Let's deep dive in to see what's beneath them.

Strict Equality Operator(===) behaves similarly to Abstract Equality Operator(==) except no type conversion is done and the types must be the same to be considered equal.

Abstract Equality Operator(==) will compare for equality after doing any necessary type conversions.

The "===" operator will NOT do any type conversions, so if the two values are not of the Same Type "===" will simply return false.


'23' == 23 // true
'23' === 23 // false

" " == 0 // true
" " === 0 // false

0 == false // true
0 === false // false

null == undefined // true
null === undefined // false

Remember devs, if you want to compare equality between two values without any unnecessary type conversion, use Strict Equality Operator(===).

I hope now you know the difference between the two operators.

Happy Coding!

Sources:

  1. MDN Web Docs
  2. StackOverflow

This article is published w/ Scattr ↗️

Top comments (0)