As a backend developer with over two years of professional experience working with Node.js and TypeScript, I’ve spent countless hours debugging and

JavaScript is broken!

submited by
Style Pass
2024-10-11 15:00:04

As a backend developer with over two years of professional experience working with Node.js and TypeScript, I’ve spent countless hours debugging and deciphering JavaScript’s sometimes baffling behaviours. Many of these quirks stem from fundamental JavaScript concepts that are easy to overlook or forget, even for seasoned developers.

Why ['2', '7', '12'].map(parseInt) Returns [2, NaN, 1]?

This behavior occurs because map() passes three arguments to the callback function: the element, the index, and the array itself. parseInt takes two arguments: the string to convert and the radix (the base for the number). So, when you use map(parseInt), the index is passed as the second argument to parseInt, causing…

Leave a Comment