JavaScript’s Peculiarities

I recently started learning JavaScript properly [the last word being the keyword]. I found a totally awesome online book, Eloquent JavaScript, and its best feature is the presence of a console and a coding area right below the text of a chapter itself. During my reading of the first few chapters, here are some points that stood out to me about JavaScript, which I have summarized below:
– When you use == to compare entities, JavaScript tries to convert the value types. So if you do not want automatic type conversion to happen, use === or !== instead
– When concatenating with a string, numbers are automatically converted to strings, e.g. “Apollo” + 5 produces “Apollo5”. “5” * 5 produces 25 on the other hand, because JavaScript tries to convert the string to a number
– NaN == NaN and NaN === NaN both return false. The way to check whether a number is NaN is using the function isNaN, e.g. isNaN(NaN)
– A return statement with no expression results in returning undefined
– A block of code within braces does not produce a new local scope – only functions can produce a new scope
– JavaScript’s == operator is equivalent to Python’s is keyword
– Arrays in JavaScript can be non-homogeneous, i.e. they might have values of all types mixed together
– In the JavaScript Date class, the month numbers start from 0 and go up to 11, which is confusing because the date numbers do start from 1
– JavaScript will not warn you if you try to use a variable name that has been taken before. It will silently execute if you assign something to var max, even though Math.max is a stardard that already exist
– [Personal opinion] Since JavaScript is not statically typed, its advanced constructs like higher order functions can become really confusing when you need to determine which arguments are functions and which arguments are values/ variables

More to come.


Leave a Reply

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

You are commenting using your 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