All JavaScript Passengers, Attention Please

This is an example why should one follow the rule of using ‘===’ and avoid ‘==’

var a = [];

[!!a, a == false] == [true, true]

You get !!a == true and at the same time a == false, now you are confused, ain’t you?

Therefore never ever you should be using in your code ‘==’ operator.

[!!a, a === false] == [true, false]
– > Feels better now, ain’t it?

“Follow the rules” is sometime a rule one should follow

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