View Full Version : difference between == and === operator
JAVAEOC
02-19-2004, 01:39 AM
the tital sais it all... i think:)
Nightfire
02-19-2004, 02:17 AM
== means equal to
=== means definately, most positively, no questions asked, equal to.
Now for the proper meanings:
Equal (==)
Returns true if the operands are equal. If the two operands are not of the same type, JavaScript attempts to convert the operands to an appropriate type for the comparison
examples
3 == var1
"3" == var1
3 == '3'
Strict equal (===)
Returns true if the operands are equal and of the same type.
example
3 === var1
in the examples, var1 has the value of 3
brothercake
02-19-2004, 02:27 AM
Originally posted by Nightfire
=== means definately, most positively, no questions asked, equal to.
:D I believe the phrase you're looking for is "strict equality"
JAVAEOC
02-19-2004, 03:00 AM
oh ok i get it but when would u need a === operator?
fredmv
02-19-2004, 03:05 AM
Originally posted by JAVAEOC
oh ok i get it but when would u need a === operator? When, as already implied, you want strict equality. The variables on each side of the operator must have equal values and of the same data type. For example, with your normal equality operator, this would return true:'3' == 3;This is because it merely checks to see if the two values are equal to each other — it doesn't care about the data type. However, when you use the strict equality operator in the same situation:'3' === 3;It will return false simply because the first is of the string data type, and the second is of the number data type.
JAVAEOC
02-20-2004, 01:05 AM
cool
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.