Created
June 12, 2015 18:11
-
-
Save timestep/afba2461ed02797d27fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var x = ['10','10','10'].map(parseInt); | |
//x === [10,Nan,2] | |
/* | |
map returns a callback with 3 arugments | |
arg[0] = elem; | |
arg[1] = index; | |
parseint takes 2 arguments | |
arg[0] = string; | |
arg[1] = radix; | |
the second argument in map passes into the second argument for parseint defining the base | |
the first element is index 0, parseInt defaults to base 10; | |
thus parseInt('10',0) = 10 | |
the second element is index 1, parseInt does not base 1, thus defaults to NaN | |
the third element is index 2, parseInt uses base 2; | |
thus parseInt('10',2) = 2 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment