Friday 18 January 2013

Difference between === and == in javascript

if(1=="1")
{
alert("hello");
}else
{
alert("hi");
}

Some time question arises that what is the output.
what you think about this ?
of course your answer is hello .
But now can you guess what is the result of following code

if(1==="1")
{

alert("hello");
}else
{
alert("hi");
}
bit confusing .
answer is hi .
It is becuase the expreesion === to compare datatype as well as value .