What is the difference between =, == and ===?

 Posted by Tripati_tutu on 11/17/2010 | Category: Sql Server Interview questions | Views: 2158 | Points: 40
Answer:

‘=’ is for assigning one value to the other variable.
‘==’ is for the comparison between string with number, number with number etc.
‘===’ is for the comparison between only number with number and string with string.

Example:
// for '=' operator
if(a=b+c)

{
alert('true')
}

It will be true if it not contains any zero, false, and any empty string.

//for '==' operator
if(a==b+c)

{
alert('true')
}

Suppose the value of x is "5" and the value of y, z is 8, -3 then the if condition will return value true. Here we are comparing string with the number.

//for '===' operator
if(x===y+z)

{
alert('true')
}

The above example is not possible for this case because x value and the result of y+z value are either number and string. It will work on the below example.

if(5 === y + z) 

{
alert('true');
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response