‘ == ‘ or ‘ === ‘ which to choose?(javascript)

In Javascript we have many types of comparison operators. out of those the most interesting and attention seeking operators are  == and ===

we shall see basing on two different factor

1)Type Casting :  

      i)   ‘ == ‘ (Equality operator) type casts if there is a necessity to do a                          type cast

e.g:- let  t=8

t == 8 (True)

t == “8” (True)

As seen even 8 in above is an integer it was typecasted                                      and as already 8 value was 8 hence 8==8 which is true

 ii)  ‘ === ‘ (Identity operator) it does no typecasting even if                                              necessary

consider t=8

e.g:- t === 8 (true)

t === ” 8 “(false)

2)Speed :-

obviously  ‘ === ‘ is way faster than  ‘ == ‘ because of no internal type checking in identity operator ( ===)

 

Note:-  there can be even other interesting difference between these two which I will discuss after I get experienced with them in my projects

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