Difference between == and === in JavaScript

So we know in javascript we have == and === comparisons. Why two? What are the differences between them?

So what is the difference between followings


'1' == 1

this returns true.

when it comes === equals


'1' === 1

this returns false.

So what it is?

The triple-equals comparator compares both type and contents

So ‘1’ === 1 contains string value and int value. Even contents are same they are in different types. So it is not equals.

Double equals tries to help with type coercion. But it’s not always the help we want. So keep in mind when you are using above equal comparisons.
 

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s