I'm new to Java Script
What is the exact difference between (== Vs ===, != Vs !==, etc) in JavaScript?
Have read some articles and wanted to be more clear on this.
Thanks in advance.
-
youtube.com/watch?v=O24XMM1PTqQLauri Elias– Lauri Elias2014-04-14 21:14:50 +00:00Commented Apr 14, 2014 at 21:14
-
if a function returns multiple values that are equivalent to false like 0, '0' or false (for example 0 means no result and false and error) and you want them to be treated the same then you can use == but if you want them to be treated differently then you have to use ===.My1– My12015-11-13 10:39:41 +00:00Commented Nov 13, 2015 at 10:39
Add a comment
|
1 Answer
The == operator means equality after type conversion
1 == '1'; // true
1 == 1; // true
The === operator means equality without any conversion
1 === '1'; // false
1 === 1; // true
3 Comments
Zini
!= and !== do the same thing but consider inequality of values converted and of types.
Anchit
'==' is used to compare only values. '===' is used to compare both value and type of the variable being compared. Both return a boolean value as result based on the comparison.