Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The 3 different equals

People also ask

What does === means?

The === operator means "is exactly equal to," matching by both value and data type. The == operator means "is equal to," matching by value only.

What does three === mean?

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'

How does == vs === differ?

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.

What does the === comparison operator do?

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