interviews.dotnetthread.com

↑ Grab this Headline Animator

Monday, November 10, 2008

what is the difference between =.== and === ?

= is meant for assigning the one value to the other
== is meant for the comparision between string with number,number with number etc
===is meant for the comparision only number with number and string with the string

Example:
//for the EQUAL OPERATOR
if(x=y+z)
{
alert('true')
}

The above condition will be true if it is not containing any zero,false,and not containing any emptystring.

//for the DOUBLE EQUAL OPERATOR
if(x==y+z)
{
alert('true')
}

suppose the value of x is "3" and y and z is 5 nad -2 then the if condition vaulue is true and alert will come.Here we are comparing string with the number.

//for the TRIPLE EQUAL OPERATOR
if(x===y+z)
{
alert('true')
}


The above example is not possible because x value and the result of y+z value are either number and string.

if (3 === y + z) {alert('true');}

The above statement will still work if one of the equals is left out and unless one or other of y and z is a string containing a three and the other is an empty string the same result will be obtained if we accidentally leave out one of the equals. If we leave out two equals this statement generates a syntax error since 3 is not a variable and we therefore can't assign a value to it.

Submit this story to DotNetKicks

No comments:

Post a Comment

Post your comments/questions/feedback for this Article.

 

Latest Articles