re: Do you know these weird parts of JavaScript? VIEW POST

re: > 0.1 + 0.2 0.30000000000000004 This is a floating point rounding error and is definitely not exclusive to JavaScript. It happens with basical...

I found that one interesting too. Took me some time.

I noticed that

['1', '7', '11'].map((n) => parseInt(n, 10))

works as expected. parseint is misinterpreting the second parameter somehow?

Then I saw docs for Array.prototype.map.

var new_array = arr.map(function callback(currentValue[, index[, array]]) {
    // Return element for new_array
}[, thisArg])

If the callback accepts a second parameter, it passes the index of the element to it. parseint does accept two parameters, but of course, it doesn't expect an index in the third one.

    parseint('1', 0),
    parseint('7', 1),
    parseint('11', 2)

And sure enough, the output confirms my theory!


you are close, if you take a look at the api doc, you will fully understand it.


parseInt(string, radix);

Yep! I'm aware. Pretty cool.

Code of Conduct Report abuse