Operator “===” / identity operator / Triple equal operator

What is Triple equal operator? Where, Why & When it’s used?

In general,

Double equal (==) is called equality operator

Tripe equal (===) is called identity operator

Here are few gotchas, you would love reading!

Where it’s used?

Seems that in PHP, RUBY (I haven’t played with them, but got to know through googling :)) & JavaScript

Why & When it’s used?

When we have a situation to check “both operands have the same value and are of the same type”.

Let’s see some examples in JavaScript:

‘1’ === ‘1’   // true – Same value and type

‘1’ === 1    // false – Same value but different type

‘1’ === true // false – Value and type are different

Equality operators also have their opposites 🙂

The non-identity operator ( !== ) returns true, where identity would return false.

‘1’ !== ‘1’   // false

‘1’ !==  1    // true

Then, is anything there in C#?

I don’t see the exact, but we have one, that helps to check for the same “instance” type, that’s it!

C# static method ReferenceEquals(obj1, obj2), helps to check same instance or reference equality.



Other useful references:



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: