To convert a string to a number in JavaScript, use the parseInt() method.

parseInt('45')  // 45
parseInt('99')  // 99
parseInt('123.jpg')  // 123

If the string is a floating-point number, use the parseFloat() method instead:

parseFloat('9.9')   // 9.9
parseFloat('60.00') // 60
parseFloat('7.5%')  // 7.5

Apart from these two methods, you can also use the Number() method, bitwise not (~), and unary operators (+, *, - and /) to perform a string to a number conversion:

// Number() Method
Number('89') // 89 
Number('45.49') // 45.49

// Bitwise Not(~)
~~'60' // 60
~~'11.89' // 11

// Unary Operators
+'20' // 20
'0xFF' - 15 // 240
'20.51' * 1 // 20.51
'30' / 2 // 15