JavaScript Number Type

From string

We can parse strings to integers and floats using the global parseInt and parseFloat functions. These functions return a number if the string input parameter can be converted to a number, and returns NaN, Not a Number, if it can't.

Code example: parseInt

const a = parseInt("12")
const b = parseInt("13.4")
const c = parseInt("abc")
console.log(a) // 12
console.log(b) // 13
console.log(c) // NaN

Code example: parseFloat

const a = parseFloat("12")
const b = parseFloat("13.4")
const c = parseFloat("abc")
console.log(a) // 12
console.log(b) // 13.4
console.log(c) // NaN