+ 12
What is the difference between == and === operators in JavaScript?
8 Respostas
+ 20
== checks both values are equal or not. and === checks both are equal or not and also types are equal or not
example
var x=5;
x =='5';
it will return true . because Values are matched
var x=5;
x ==='5';
it will return false. because values are matched but data type is different. Variable x having integer value which is compared with string value(written in ' ' )
+ 5
== checks only values, === checks both values and types
+ 4
=== in JavaScript is called as strict equal operator and == operator is known as equality operator.
the output given by === is more precise than the == in JavaScript
+ 2
== checks both values are equal or not. and === checks both are equal or not and also types are equal or not
example
var x=5;
x =='5';
it will return true . because Values are matched
var x=5;
x ==='5';
it will return false. because values are matched but data type is different. Variable x having integer value which is compared with string value(written in ' ' )
+ 2
== means both values have content comparison
=== means it will check both values of their datatypes
+ 2
== will at first converts them into same type(usually number) and then compares them, the === operator only compares. You can find more information about the algorithm of the == operator here in the section 11.9.3 https://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3
+ 2
== just to check the equality
=== is to check the identity.
when using ===, the both value and the type must be same. when i say the type, i mean object, string, etc.
if u compare an object and a string having same value and using === to compare them. you will get false result.