65.9K
CodeProject is changing. Read more.
Home

Javascript Operators === & !==

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.33/5 (6 votes)

Feb 22, 2011

CPOL
viewsIcon

21702

Javascript Operators === & !==

The following example will demonstrate the Tip:
var x;
x = 0;
var y;
y = '0';
x is numeric, while y is char. On comparing them using the "==" operator, it will give true !
alert('x == y : ' + (x==y));
To do so, we will use the '===' operator:
alert('x === y : ' + (x===y));
which checks on the Value and Type, so it will give false. Same for the !== operator.
alert('x != y: '; + (x != y));
it gives false !!
alert('x !== y: '; + (x !== y));
it gives true So, to assure an accurate comparison datatype and value don't use the normal operators == and != but use === and !== operators.