Skip to content

Instantly share code, notes, and snippets.

@timestep
Created June 12, 2015 18:11
Show Gist options
  • Save timestep/afba2461ed02797d27fb to your computer and use it in GitHub Desktop.
Save timestep/afba2461ed02797d27fb to your computer and use it in GitHub Desktop.
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