JavaScript Code

How to convert string to integer in JavaScript?

Convert string to integer in JavaScript

In this tutorial, you are given a string value. You should convert the string to an integer type value.


To convert a given string into integer, use JavaScript global function parseInt(). Pass the string as argument to parseInt() function, and the function returns the integer value.


str is the given string value. we use parseInt() method to parse the string str into an integer.

let str = "45";
let num = parseInt(str);