Live data from Hacker News

Stranger Things, JavaScript Edition

livecodestream.dev

31–40 of 58 posts

Re: Stranger Things, JavaScript Edition

#31
post #30
post #28

Earlier quoted context omitted.

But you're not getting the wrong answer, it's doing exactly what it should do. That one isn't really even a weird language quirk like the others. It's just assuming you're not aware that parseInt can take a 2nd argument

The issue doesn't arise because of parseInt() being able to take more than one argument, the issue is that map() is passing not only the value in the array but also its index as well as a copy of the full array. I use map() all the time but I didn't know about that until I read this article. I wonder why map() functions this way in Javascript and if any other languages pass additional values like this in their own ma…

> I wonder why map() functions this way in Javascript and if any other languages pass additional values like this in their own map() implementations.

Sometimes it's very convenient to be able to look ahead or behind the current element being map()'d to make decisions.

Re: Stranger Things, JavaScript Edition

#32
post #29

Earlier quoted context omitted.

I used to hate it. Now I'm meh. I'm on the middle ground!

I'm with you, but I think the parent comment is right. Because generally comments here are either over-criticizing or over-defending JS.

The language has finally achieved "meh" status if you can use only the latest version and ignore at least half of it completely. This may or many not still make it very bad or entirely fine depending on one's perspective.

Re: Stranger Things, JavaScript Edition

#33
post #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 conv…

I have a bit of a hard time with you there, I like to use maps in my code and trying to map a parser over a list of strings and getting the wrong answer is far from 'of no consequence' to me. I'm not saying these issues make the language unusable, but you've got to be a bit more honest that you were if you want to be taken seriously.

Good linter will warn you that you are using parseInt without second parameter.

Re: Stranger Things, JavaScript Edition

#34
post #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 conv…

I have a bit of a hard time with you there, I like to use maps in my code and trying to map a parser over a list of strings and getting the wrong answer is far from 'of no consequence' to me. I'm not saying these issues make the language unusable, but you've got to be a bit more honest that you were if you want to be taken seriously.

"If I want to be taken seriously?" Was that bit of petty oneupmanship really necessary? I assure you, Alex, I'm completely unconcerned with whether you take me seriously.

You were probably just trying to show off. But in case you weren't, here's how JS works.

In JavaScript, if you're passing in a function as a parameter, the normal way is to use an arrow function. Like this: `array.map((element) => yourFunction(element));`. This gives you explicit control over which parameters are passed in to your function and how.

As a shortcut, you can provide a function name rather than an arrow function. If you do so, you're saying that you want all parameters to be passed to that function. You're expected to know what those parameters are and how the function you're passing in will use them. If you don't know that, well, you're programming blind and bad things will sometimes happen. Maybe don't do that.

As with many things in JavaScript, it's better to be explicit than rely on the shortcut.

Edit: Just to be clear, here's the correct way to map an array of strings to an array of numbers in JavaScript: `array.map((s) => parseInt(s, 10));`

Re: Stranger Things, JavaScript Edition

#36

It doesn’t help that JS initially had no formal specification. So every implementation had their quirks (because there were no grammar or implementation tests). Later formal standards created the “use strict” feature which alleviates a lot of problems.

In the beginning, there was just a single vendor (Netscape) and a single implementation (Netscape Navigator). Then there was also a license and a non compliant implentation and things became a bit weird. (E.g., missing implementations of standard functions or missing bound checks.) However there were definitions of the core language available from Netscape for each of the versions, even before the ECMA standard.

Re: Stranger Things, JavaScript Edition

#37

Either you love it or you hate it, there's no middle ground with JavaScript

I used to hate it. Now I'm meh. I'm on the middle ground!

I used to love it, now I'm meh. I love some things about it (ecosystem, dev mindshare), now don't like some things (dependency hell, lack of proper debugger, always single-threaded).

Re: Stranger Things, JavaScript Edition

#39
post #38
post #35

Another fun one to figure out is: 072 === 058 // returns true Thankfully, doesn't work in strict mode.

If that is a combination of octal and decimal how is 058 not a parser error?

`072` is interpreted as octal, and `058` is interpreted as decimal (7·8+2 = 58). Ah, the dumpster fire that is JavaScript.

Re: Stranger Things, JavaScript Edition

#40
post #30
post #28

Earlier quoted context omitted.

But you're not getting the wrong answer, it's doing exactly what it should do. That one isn't really even a weird language quirk like the others. It's just assuming you're not aware that parseInt can take a 2nd argument

The issue doesn't arise because of parseInt() being able to take more than one argument, the issue is that map() is passing not only the value in the array but also its index as well as a copy of the full array. I use map() all the time but I didn't know about that until I read this article. I wonder why map() functions this way in Javascript and if any other languages pass additional values like this in their own ma…

Where do your expectations come from though?

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

Post reply on HN