Need Help With Javascript Development?

Work with our skilled Javascript developers to accelerate your project and boost its performance.

Hire JavaScript Developers

Support On Demand!

Here are some ways to convert a String to an Int in javascript:

1. parseInt() function:

var str = "123";
var num = parseInt(str);

2. Number constructor:

var str = "123";
var num = Number(str);

3. + (Unary Plus) Operator:

var str = "123";
var num = +str;

4. Bitwise OR | Operator:

var str = "123";
var num = str | 0;

Note: In above examples, if given input can not be converted to number then first three methods will return NaN and 4th will return 0.

Related Q&A