# Why [`'`1`'`, `'`7`'`, `'`11`'`].map(parseInt) returns [1, NaN, 3] in Javascript

`['1', '7', '11'].map(parseInt);`

# Truthiness & Falsiness

`if (true) {    // this always runs} else {    // this never runs}`
`if ("hello world") {    // will this run?    console.log("Condition is truthy");} else {    // or this?    console.log("Condition is falsy");}`

`0 1 2 3 4 5 6 7 8 9 10`
`DECIMAL   BINARY    HEXADECIMALRADIX=10  RADIX=2   RADIX=160         0         01         1         12         10        23         11        34         100       45         101       56         110       67         111       78         1000      89         1001      910        1010      A11        1011      B12        1100      C13        1101      D14        1110      E15        1111      F16        10000     1017        10001     11`

# Function arguments

`function foo(x, y) {    console.log(x);    console.log(y);}foo(1, 2);      // logs 1, 2foo(1);         // logs 1, undefinedfoo(1, 2, 3);   // logs 1, 2`

# map()

`function multiplyBy3(x) {    return x * 3;}const result = [1, 2, 3, 4, 5].map(multiplyBy3);console.log(result);   // logs [3, 6, 9, 12, 15];`
`[1, 2, 3, 4, 5].map(console.log);`
`[1, 2, 3, 4, 5].map(console.log);// The above is equivalent to[1, 2, 3, 4, 5].map(    (val, index, array) => console.log(val, index, array));// and not equivalent to[1, 2, 3, 4, 5].map(    val => console.log(val));`

# Bringing it together

`parseInt('11');                => 11parseInt('11', 2);             => 3parseInt('11', 16);            => 17parseInt('11', undefined);     => 11 (radix is falsy)parseInt('11', 0);             => 11 (radix is falsy)`
`['1', '7', '11'].map(parseInt);       => [1, NaN, 3]// First iteration: val = '1', index = 0, array = ['1', '7', '11']parseInt('1', 0, ['1', '7', '11']);   => 1`
`// Second iteration: val = '7', index = 1, array = ['1', '7', '11']parseInt('7', 1, ['1', '7', '11']);   => NaN`
`// Third iteration: val = '11', index = 2, array = ['1', '7', '11']parseInt('11', 2, ['1', '7', '11']);   => 3`

# Summary (TLDR)

`['1', '7', '11'].map(numStr => parseInt(numStr));`

Written by