3
0 Comments

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 the datatype is the 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.

strict-equality

Loose Equality (==)

Loose equality works similarly 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.

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://www.getrevue.co/profile/8020lessons

posted to Icon for group Developers
Developers
on November 4, 2021
Trending on Indie Hackers
Stop losing deals in the gap between "sounds good" and getting paid User Avatar 64 comments Building a startup costs $0. Your tooling budget costs $500K. Here's why. User Avatar 50 comments We scanned 50,000 domains. Your cold email list is really four systems. User Avatar 47 comments 787 tools for developers. 5 for nurses. Two weeks of tracking 14,000 indie launches. User Avatar 38 comments 67K impressions in 2 days from a single Daily-Dev post — here's what happened User Avatar 24 comments 🚀 I built Brickbeam — an AI-powered assistant that helps LEGO fans turn their messy piles of bricks into real builds. User Avatar 21 comments