What is the use of identical(===) when we should compare with same data type using (==) ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What is the use of identical(===) when we should compare with same data type using (==) ?

18th Dec 2015, 2:23 AM
sreedhar
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.
26th Dec 2015, 7:43 PM
Nikolay Matev
Nikolay Matev - avatar
+ 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
5th Sep 2016, 3:35 AM
Aniekan
Aniekan - avatar
0
In real life, strict equality is almost always the correct comparison to use.
25th Nov 2016, 12:41 PM
Kristjan
Kristjan - avatar