Wednesday 27 May 2015

javascript == and === difference

1. === operater
=== means value must be equal and type as well
Ex:
var value1=1;
var value2='1';

if(value1===value2) /// this will return false because this value type is different(javascript will do internal type casting even though if we use === it will follow the strict rules),

and

if(0===false) // this will return false because different data type


2.== operator

== means value must be equal,

Ex:
var value1=1;
var value2='1';
if(value1==value2) /// this will return true because (==) will check only value(javascript handle type conversion).

and
if(0==false) // this will return true because false is equal to 0

No comments:

Post a Comment