+ 3
What is the use of identical(===) when we should compare with same data type using (==) ?
3 Answers
+ 7
The strict equal "===" will check if the data types are also equal. Example is:
1 == "1"
// Returns "true"
1 === "1"
// Returns "false"
As everything between quotes gets string data type, and not number data type as the other 1, the strict equal operator detects the difference.
+ 2
Both == and === are comparison/logical operators. However, '==' compares/checks for just equality in value (both values are the same value ) while "===" operator checks for sameness in both value and type.
1 == "1" is true because they have the same value
1 === "1" is false because even though they have the same value, they are not of the same type. The first is a number while the second is a string
0
In real life, strict equality is almost always the correct comparison to use.