Since PHP and JavaScript are weakly typed, sometimes using ==
will cause unwanted coercions (e.g., convert a string to a number). The ===
operator is an identity operator—it only returns true if both operands are the same object.
+2
A:
Mark Cidade
2010-09-20 07:39:01
+2
A:
== is a value based comparison on javascript. Such as
x = 5
x == '5' //True
=== is a value and type based comparison so;
x = 5
x ==='5' //False, becaouse diffrent types
FallenAngel
2010-09-20 07:39:41
+1
A:
'===' means exactly equal whereas '==' means equivalent within the current context.
This makes a big difference when comparing numbers as the following code snippet illustrates (stolen from the php docs):
<?php
$first = 10;
$second = 10.0;
$third = "10";
if ($first == 10) print "One";
if ($second == 10) print "Two";
if ($third == 10) print "Three";
if ($third === 10) print "Four";
if ($second === 10) print "Five";
if ($first === 10) print "Six";
?>
Will print out
OneTwoThreeSix
James Anderson
2010-09-20 07:45:13
A:
in PHP, the extra = sign makes it absolute equality operator (===), which ensures/tests whether two values are the same and of the same data type, thus adding precision to comparisons. Here's a nice read from tuxradar: http://www.tuxradar.com/practicalphp/3/12/2
bhu1st
2010-09-20 07:51:50