Live data from Hacker News

Stranger Things, JavaScript Edition

livecodestream.dev

1–10 of 58 posts

Re: Stranger Things, JavaScript Edition

#4
This article is written like these flaws in javascript are just a quirky feature.

No, they are an embarrassment.

They don't make the language cool or interesting, they aren't tricks. They are logically incoherent nonsense.

Re: Stranger Things, JavaScript Edition

#6
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!

Re: Stranger Things, JavaScript Edition

#9
This code snippets are the JavaScript equivalent of the Obsfucated C contest: amusing for insiders, a source of smug satisfaction for language warriors, and ultimately of no consequence to day-to-day practitioners.

There is a relatively small list of "gotchas" in JavaScript that stem from the early days of the language. They are easily avoided. Use a linter, "use strict," use ===, and be explicit about your type conversions.

Re: Stranger Things, JavaScript Edition

#10
post #6

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…

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.

Post reply on HN