Live data from Hacker News

The Birth and Death of JavaScript [video]

destroyallsoftware.com

21–30 of 236 posts

Re: The Birth and Death of JavaScript [video]

#22
post #4

I'm missing some obvious joke...but why is he pronouncing it yava-script.

I thought it was supposed to be some future pronunciation thing, imagining the way languages evolve. I've seen SciFi movies where in the future english is heavily influenced by spanish.

Re: The Birth and Death of JavaScript [video]

#26

> xs = ['10', '10', '10'] > xs.map(parseInt) [10, NaN, 2] Javascript is beautiful.

It's due to parseInt having an optional second parameter, the radix, and map passing the index as the second paramater, hence:

  xs = [
    parseInt('10', 0),
    parseInt('10', 1),
    parseInt('10', 2)
  ]

Re: The Birth and Death of JavaScript [video]

#28

> xs = ['10', '10', '10'] > xs.map(parseInt) [10, NaN, 2] Javascript is beautiful.

It's due to parseInt having an optional second parameter, the radix, and map passing the index as the second paramater, hence: xs = [ parseInt('10', 0), parseInt('10', 1), parseInt('10', 2) ]

And since 0 is falsy we get 10 for base 0.

Re: The Birth and Death of JavaScript [video]

#29

> xs = ['10', '10', '10'] > xs.map(parseInt) [10, NaN, 2] Javascript is beautiful.

There are so many good WTFs in JS, but this is not one. parseInt expects 2 arguments and Array.prototype.map provides 3 to the callback it is given. Both of these facts are very well documented and known.

    var mappableParseInt = function(str){
        return parseInt(str, 10);
    };

    ['10', '10', '10'].map(mappableParseInt);
I'd suspect this snippet is more a snipe at people who don't know JS very well and expect parseInt to be base-10 only.

Re: The Birth and Death of JavaScript [video]

#30

Earlier quoted context omitted.

It's due to parseInt having an optional second parameter, the radix, and map passing the index as the second paramater, hence: xs = [ parseInt('10', 0), parseInt('10', 1), parseInt('10', 2) ]

And since 0 is falsy we get 10 for base 0.

Which is odd. I wonder why they checked for falsiness and not the argument being undefined.
Post reply on HN