const myNumber = '1'; console.log(+myNumber);
const myNumber = '1.5'; console.log(+myNumber);
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:
parseInt
10
console.log([ parseInt('ff', 16), parseInt('a5', 16), parseInt('00', 16) ]);
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Shorter.
By the way, you will need
parseInt
anyway, if you want to deal with custom base number other than10
. Example is to convert HEX color code into RGB color code: