The parseInt() method in JavaScript converts a string into a number. The method returns NaN if the value entered cannot be converted to a number.
Example
You can try to run the following code to convert a string into an integer −
<!DOCTYPE html> <html> <body> <button onclick = "display()">Check</button> <p id = "demo"></p> <script> function display() { var val1 = parseInt("50") + "<br>"; var val2 = parseInt("52.40") + "<br>"; var val3 = parseInt(" 75 ") + "<br>"; var res = val1 + val2 + val3; document.getElementById("demo").innerHTML = res; } </script> </body> </html>