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…


This content originally appeared on DEV Community and was authored by Swastik Yadav

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.

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.

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


This content originally appeared on DEV Community and was authored by Swastik Yadav


Print Share Comment Cite Upload Translate Updates
APA

Swastik Yadav | Sciencx (2021-11-04T06:10:40+00:00) JavaScript Loose Equality vs Strict Equality check. Retrieved from https://www.scien.cx/2021/11/04/javascript-loose-equality-vs-strict-equality-check/

MLA
" » JavaScript Loose Equality vs Strict Equality check." Swastik Yadav | Sciencx - Thursday November 4, 2021, https://www.scien.cx/2021/11/04/javascript-loose-equality-vs-strict-equality-check/
HARVARD
Swastik Yadav | Sciencx Thursday November 4, 2021 » JavaScript Loose Equality vs Strict Equality check., viewed ,<https://www.scien.cx/2021/11/04/javascript-loose-equality-vs-strict-equality-check/>
VANCOUVER
Swastik Yadav | Sciencx - » JavaScript Loose Equality vs Strict Equality check. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/04/javascript-loose-equality-vs-strict-equality-check/
CHICAGO
" » JavaScript Loose Equality vs Strict Equality check." Swastik Yadav | Sciencx - Accessed . https://www.scien.cx/2021/11/04/javascript-loose-equality-vs-strict-equality-check/
IEEE
" » JavaScript Loose Equality vs Strict Equality check." Swastik Yadav | Sciencx [Online]. Available: https://www.scien.cx/2021/11/04/javascript-loose-equality-vs-strict-equality-check/. [Accessed: ]
rf:citation
» JavaScript Loose Equality vs Strict Equality check | Swastik Yadav | Sciencx | https://www.scien.cx/2021/11/04/javascript-loose-equality-vs-strict-equality-check/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.