Anthony Lee

Javascript: The Good Parts

Introduction

user

Anthony Lee

I love to code and better the world. Graduate student at Georgia Tech specializing in Machine Learning.


Featured

Javascript

Javascript: The Good Parts

Posted by Anthony Lee on .

Most programmers love to hate Javascript, because some of the bad parts of the language are really bad while some of the good parts of the language are really good.

One of my favorite programming book is Javascript: The Good Parts written by Douglas Crokford, who is known for his involvement with JSON, JSLint, and more.

For next few blog posts, I am hoping to concentrate on writting more about his point of views regarding Javascript. If you are like me who writes code for the web, Javascript is an essential language for you to master. Douglas will teach you some great parts of the language while warning you about the bad parts. I highly encourage you to read his book.


For this post, let’s look at a simple example of double equal operator in Javascript. It is supposed to be a equality operator, but because it performs coercion prior to comparison in Javascript—it can lead to false positives. If you are new to the language, a simple thing like that can make mathematical law of transitivity a nightmare.

Here are some examples:

0 == ''           //true
0 == '0'          //true
'' == '0'         //false
fasle == 'false'  //false
false == '0'      //true
" \t\r\n " == 0   //true

When you are writting code, one of the things you want to make sure is that it is not confusing. For this very reason, Douglas argues we should always use ===, and never == for comparison.

I agree.

user

Anthony Lee

http://anthonylee.io

I love to code and better the world. Graduate student at Georgia Tech specializing in Machine Learning.