In this quick tip, you’ll learn how to convert string to number in JavaScript. For example, how to convert “123” to 123.

Using Number method

You can use the Number method to convert a string to number.

function stringToNumber(input){
  return Number(input)
}

console.log(stringToNumber("123")) 
// outputs 123

It also works fine in case of decimal points.

function stringToNumber(input){
  return Number(input)
}

console.log(stringToNumber("123.1234")) 
// outputs 123.1234