Equal to v/s Strictly Equal to


What’s the difference between equal to v/s strictly equal to and not equal to v/s strictly not equal to in any programming language?

This seems to be confusing at first, but if we execute a small example things get very clear about the working of these operators.

strictly-not-equal-to

== is called equal to operator.
!= is called not-equal to operator.
=== is called strictly equal to operator.
!== is called strictly not-equal to operator.

In this video tutorial we shall see the differences between == v/s === and != v/s !===

Difference between != v/s !=== and == v/s ===


[youtube https://www.youtube.com/watch?v=ql5cS8DntwQ]

YouTube Link: https://www.youtube.com/watch?v=ql5cS8DntwQ [Watch the Video In Full Screen.]



$a = 1;
$b = '1';

Lets assign integer 1 to variable a and string ‘1’ to variable b.

Equal-to v/s Strictly Equal-to

$a == $b
true
 
$a === $b
false

== operator doesn’t consider the type of variable strictly, thus returns true even though we are comparing a string with an integer. But === operator considers the type of the variable strictly and treats integer and string as two different things and hence returns false.

Not Equal-to v/s Strictly Not Equal-to

$a != $b
false
 
$a !== $b
true

Similarly, as != operator doesn’t take variable type into strict consideration it thinks $a and $b as equals, hence returns false, but !== returns true as it reads integer and string variables as different.

Leave a Reply

Your email address will not be published. Required fields are marked *