DEV Community

Cover image for JavaScript Loose Equality vs Strict Equality check
Swastik Yadav
Swastik Yadav

Posted on • Edited on

7 2

JavaScript Loose Equality vs Strict Equality check

Hello Everyone!

In this post we will explore the difference between JS loose equality (==) and strict equality (===) check.

Here is the simplest definition

  • Loose equality (==) checks for value only.
  • Strict equality (===) checks for value as well as DataType.

But wait, there is something more to it. Let's understand the workings of both of them one by one.

Strict Equality (===)

Strict equality first checks for DataType, If datatype is same then it checks for value, else it returns false.

Ex:

console.log("55" === 55);
// false - Because datatype is different even though value is same.
Enter fullscreen mode Exit fullscreen mode

strict-equality

Loose Equality (==)

Loose equality works similar to strict equality. The only difference is that in loose equality if datatype is different, it performs an Implicit type conversion and then compares the value.

Ex:

console.log("55" == 55);
// true - Because implicit conversion will change string "55" to number 55 then compare value.
Enter fullscreen mode Exit fullscreen mode

loose-equality

If you enjoyed or found this post helpful, please consider joining my weekly Newsletter below.

Thank You for reading.


I am starting a NewsLetter where I will share epic content on building your skillset. So, if this sounds interesting to you, subscribe here: https://swastikyadav.com

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

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

Okay