DEV Community

Discussion on: You should stop using `parseInt()`

Collapse
 
taufik_nurrohman profile image
Taufik Nurrohman • Edited
const myNumber = '1';
console.log(+myNumber);
Enter fullscreen mode Exit fullscreen mode
const myNumber = '1.5';
console.log(+myNumber);
Enter fullscreen mode Exit fullscreen mode

Shorter.

By the way, you will need parseInt anyway, if you want to deal with custom base number other than 10. Example is to convert HEX color code into RGB color code:

console.log([
    parseInt('ff', 16),
    parseInt('a5', 16),
    parseInt('00', 16)
]);
Enter fullscreen mode Exit fullscreen mode