Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the "===" operator for?

Tags:

operators

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 ??

like image 348
Sachindra Avatar asked Mar 19 '10 09:03

Sachindra


People also ask

What does === mean?

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 is the === operator in Java?

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.

What does === mean in coding?

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 ...

What is the difference between == and === operators?

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.


Video Answer


2 Answers

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.

like image 67
Michael Aaron Safyan Avatar answered Sep 23 '22 01:09

Michael Aaron Safyan


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, !==.

like image 40
bcherry Avatar answered Sep 22 '22 01:09

bcherry