I once encountered an operator "===". But I don remember what it was.. or where do we use it .. or is there any such a kind of operator ? where is it used ??
Its used in JavaScript, PHP and may be more (which I may not have encountered yet!), it is used to compare if both the compared things are of same object type as well as have same value.
=== is equality, at least in PHP
Here is a link that helps explain thsi
It usually tests if two objects are the same. ie. not if they have the same value(s) but if they really are the same object.
In JavaScript, ==
does type coercion, while ===
, the "strict equality" operator does not. For example:
"1" == 1; // true
"1" === 1; // false
There is also a corresponding strict inequality operator, !==
.
"===" operator is used to check the values are equal as well as same type.
Example
$a === $b if $a is equal to $b, and they are of the same type.
In PHP, JavaScript, ECMAScript, ActionScript 3.0, and a number of other similar, dynamic languages, there are two types of equality checks: == (non-strict equality) and === (strict equality). To show an example:
5 == "5" // yep, these are equal, because "5" becomes 5 when converted to int 5 === 5 // nope, these have a different type
Basically, whenever you use ==, you risk automatic type conversions. Using === ensures that the values are logically equal AND the types of the objects are also equal.