DEV Community

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

Posted on • Originally published at rajkishor.hashnode.dev

1

'==' 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 ↗️

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay