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 ??
The === operator means "is exactly equal to," matching by both value and data type. The == operator means "is equal to," matching by value only.
In weakly typed languages such as JavaScript you can use the strict comparison operator ( === ) because the language allows comparison between variables which have different types. For example, in JavaScript, you won't get a compile error if you do this: var x = 10; var y = 'foo'; console.log(x == y); // false.
1) When we compare two variables of different type e.g. a boolean with a string or a number with String using == operator, it automatically converts one type into another and return value based upon content equality, while === operator is strict equality operator in Java, and only return true if both variable of same ...
No. Double equals named as Equality Operator. Triple equals named as Identity / Strict equality Operator. Triple equals used as Strict conversion without performing any conversion in operands.
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.
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, !==
.
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