Skip to main content

Command Palette

Search for a command to run...

Difference between == VS ===

Published
โ€ข1 min readโ€ขView as Markdown
Difference between == VS ===
const Num1 = 1;
const Num2 = 1;
console.log(Num1 == Num2); //output is true
console.log(Num1 === Num2); // output is true

๐Ÿ’ก Now you will say, Whatโ€™s new in this!!!!

**const Num1 = 1;
const string = โ€œ1โ€; // string is here
console.log(Num1 == Num2); // True
console.log(Num1 === Num2); // False**

Let me explain to you Now!!!!!

\== called a Double Operator, Known as Equality or abstract Comparison

\=== called as Triple Operator, Known as Identity or Strict Comparision

Performance is totally irrelevant, == vs === is faster is a myth

== converts the variable values to the same type before performing the comparison.

const num = 1;
const num1 = โ€œ1โ€;
console.log(num == num1); // Returns TRUE

๐Ÿ’ก // This returns true as it is converted the type, And so if it is false also it returns True

=== does not do any type of conversion (coercion) and returns true

only if both values and types are identical for the two variables

const num = 1;
const num1 = โ€œ1โ€;
console.log(num == num1); // Returns FALSE

๐Ÿ’ก // This returns False, as the type remains Identical

https://media.tenor.com/tYaTvtWlTF4AAAAC/abhi-mereko-samajh-me-aaya-iska-actually-problem-kya-hai-johnny-lever.gif

Chalo shuru karo Abb!!!!!!!๐Ÿ™Œ๐Ÿ™Œ๐Ÿ™Œ๐Ÿ™Œ๐Ÿ™Œ๐Ÿ™Œ