The === operator means "is exactly equal to," matching by both value and data type. The == operator means "is equal to," matching by value only.
The triple equal sign is the one you're probably familiar with. It tests for strict equality between two values. Both the type and the value you're comparing have to be exactly the same. Examples of strict equality: 3 === 3. // true (Both numbers, equal values)'test' === 'test'
The main difference between the == and === operator in javascript is that the == operator does the type conversion of the operands before comparison, whereas the === operator compares the values as well as the data types of the operands.
The strict equality operator ( === ) checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.
You have =
the assignment operator, ==
the 'equal' comparison operator and ===
the 'identical' comparison operator.
$a = $b Assign Sets $a to be equal to $b.
$a == $b Equal TRUE if $a is equal to $b.
$a === $b Identical TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4)
For more info on the need for ==
and ===
, and situations to use each, look at the docs.
=
is the assignment operator ==
is the comparison operator (checks if
two variables have equal values)===
is the identical comparison
operator (checks if two variables
have equal values and are of the same
type).= assignment operator
== checks if two variables have the same value
=== checks if two variables have the same value AND if their types are the same
The = operator assigns the value to a variable $six = 6; value 6 is assigned to variable $six
== operator check if the value of both variables is equal and mostly used in conditions like if statements
$a = 2;
$b = 2;
if ($a == $b) {
echo both variables have the same value;
}
=== operator similar to == (check if the value equals) and also check if both of same data type
$a = 2;
$b = "2";
if ($a === $b) {
echo "both variable have same value and of same data type";
} else {
echo 'both variable is either not equal or not of same data type';
}
// here $a is of type int whereas $b is of type string. So here the output
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With