tags:

views:

193

answers:

6

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

+7  A: 

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.

Mahesh Velaga
Also used in PHP..
Aviator
Not only JS. Also in a lot other languages.
Felix Kling
@Aviator @ Felix thanks for pointing out, edited :)
Mahesh Velaga
+1  A: 

=== is equality, at least in PHP

Here is a link that helps explain thsi

Chris
And in Prolog too, as I recall. I'm not certain.
MatrixFrog
+1  A: 

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.

Kristian Hebert
+8  A: 

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

bcherry
+2  A: 

"===" 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.
muruga
+1  A: 

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.

Michael Aaron Safyan
Is there any difference between Javascript and ECMAScript?
xiao
@Turtle, yes. ECMAScript is the language standardization effort on which JavaScript is now based (JavaScript came first), and there are many languages -- not just JavaScript -- that derive their core syntax from ECMAScript but then add other elements or constructs (e.g. ActionScript 3.0). The key difference between JavaScript and ECMAScript, is that JavaScript is ECMAScript as it occurs in practice... i.e., how browsers actually implement ECMAScript (such as deviations from the standard, extensions, etc.)
Michael Aaron Safyan