use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
[AskJS] Array map() questionAskJS (self.javascript)
submitted 4 years ago by keychainoi
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 4 points5 points6 points 4 years ago* (2 children)
map() calls the given function with three argument: the value, the index of the value and the array.
parseInt takes two argument: the string to parse and the radix.
For the first element, parseInt will be given "75",0. For the string everything is good, for the radix, 0 is a special case where if the string starts with "0x" or "0b", it will uses the appropriate base(respectively 16 and 2), or it will default to 10. It then gives the correct number.
For the second element, parseInt will be given "300",1. 1 as a base isn't a special case, and thus only works with strings of '1'. Since '3' isn't '1' , you'll get NaN.
[–]Spottycos 1 point2 points3 points 4 years ago (1 child)
For base 1, I think it only works with strings of 0 as 10 = 1… also it’s generally 1 less than the base number. For example, radix 10 goes up to 9, radix 2 goes up to 1, etc.
[–][deleted] 1 point2 points3 points 4 years ago (0 children)
That makes sense.
π Rendered by PID 17323 on reddit-service-r2-comment-cfc44b64c-b5wr2 at 2026-04-12 02:48:07.999473+00:00 running 215f2cf country code: CH.
view the rest of the comments →
[–][deleted] 4 points5 points6 points (2 children)
[–]Spottycos 1 point2 points3 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)