How to parse string "000" to number in java script

Viewed 60

I have string "000" and I want to convert it to a number 000.

parseInt and Number parse it to 0.

I try this:

const number = '0000';
const parseNumber = parseInt(number, 10);
console.log(parseNumber); // the output is 0 :/

thanks :)

1 Answers

Actually, there is no way to do this because 000 is equivalent to 0! If you want to do some arithmatic operations then simply use 0. If you want to just output 000, then use it as a string.

Related