Use of === operator in Javascript

The === operator is used in JavaScript to compare the values of two operands. It checks if the operands have the same value and also checks if they have the same type. This is known as strict equality, and it is different from the == operator, which only checks for value equality and does not check for type.
The = is simply an assignment to a variable.
 
The === operator is used in JavaScript to compare the values of two operands. It checks if the operands have the same value and also checks if they have the same type. This is known as strict equality, and it is different from the == operator, which only checks for value equality and does not check for type.
The = is simply an assignment to a variable.
Just like this, example:
JavaScript:
console.log(1 == "1"); // true, because the values are equal
console.log(1 === "1"); // false, because the types are not equal
 
the === operator in JavaScript is used for strict equality comparisons, checking both the value and data type of two values.
  • 5 === 5; // true (both are numbers with the same value)
  • "hello" === "hello"; // true (both are strings with the same value)
  • 5 === "5"; // false (different data types)
  • 5 === 6; // false (different values)
 
to avoid type casting use strict comparison ====
otherwise string like '2' will be transformed into 2 when you are comparing 2 and '2' with ==
Also you can face some other bugs with that
I see no reason to use ==
 
The === operator in JavaScript is the strict equality operator. It checks both the value and the type for equality
 
Back
Top