If you are a JS developer, this doesn't come as a surprise. Since I'm not:

['1', '7', '11'].map(parseInt) returns [1, NaN, 3]

· · Web · 2 · 1 · 3

@ruivieira the #35c3 junior ctf had a whole section about types in JS and it was amazing and educational

That kind of makes sense, given that passes the value and the index in the array to the function you're calling, and parseInt is meant to take two params (even though we all just assume a base of 10 is the default). JS has far more peculiar things than that. E.g. {} + {} returns NaN but [] + [] returns "", or that NaN === NaN is false, and that typeof NaN returns "number", or that "3" + 1 returns "31" but "3" - 1 returns 2... crazy language!

@mynamesleon Yes, it's a case of RTFM! :)

As someone pointed:

['1', '7', '11'].map(Number)

gives (my) expected result.

Sign in to participate in the conversation
Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!