Javascript TUTORIAL
Difference between == and ===
JavaScript has two sets of equality operators === and the ==. They have corresponding negated equality operator !== and !=.
So what is the difference and how and when to use these ?
If the two operands are of the same type and have the same value, then === produces true. Its twin == does the same thing if the two operands are of the same type and same value. The difference is when the two operands are NOT of the same type. For example when one of them is a string and other is an integer.
Example
var x=5 ;
var y="5";
X === y; // false;
x == y; // true
Here is complete working example
<html> <body> <script type="text/javascript"> <!-- /* Example Illustrating the difference between === and == */ var x=5 ; var y="5"; if (x === y) { document.write("x===y is true"); } else { document.write("x===y is false");; } document.write("<br />"); if (x == y) { document.write("x==y is true"); } else { document.write("x==y is false"); } //--> </script> </body> </html> |
Try this Example online
You can try this example online at - here .