Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Say what you will about the fact that these exist in the language, I found this post interesting because although realistically and thankfully I never have to deal with these quirks day-to-day, it brought me more insight to the weird nature of this language.

More specifically, the first one was quite interesting and subtle enough that if I didn't have the `parseInt(N, 10)` rule ingrained in my head, if I had to parse a list of numbers I would try that and then scratch my head for like 30 minutes being very confused. It's also subtle enough that I could see it possibly going to production, because it could be missed if the code is only lightly tested and could be missed in a code review too.

The other one that intrigued me was the second one, and I had to look up why it works -- I didn't realize that using the + operator turns any non-parseable value into NaN.

Thanks for the cool article!



I recommend people to study few things before jumping in to something complex which will help them deal with the mess -

Understand the difference between primitive values and object values. There are few historical bugs here with typeof that are now defined in the spec (null, undefined etc are primitive values but will give object etc).

Floating point math:

https://en.m.wikipedia.org/wiki/Floating-point_arithmetic

Type coercion:

https://exploringjs.com/deep-js/ch_type-coercion.html

Prototypical inheritance:

https://javascript.info/prototype-inheritance

How this works:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

And you will be fine for the most part. Other things you will discover on your own.

And use typescript if you can.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: