
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How do I convert a string into an integer in JavaScript?
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>
- Related Articles
- How do I convert an integer to binary in JavaScript?
- How to convert a string into integer in JavaScript?
- How to convert a string into an integer without using parseInt() function in JavaScript?
- How do I convert a double into a string in C++?
- How to convert a string vector into an integer vector in R?
- Haskell Program to convert the string into an integer
- C++ Program to convert the string into an integer
- How to convert an array into JavaScript string?
- How to convert a string of any base to an integer in JavaScript?
- How to convert an integer into a date object in Python?
- How do I search through an array using a string, which is split into an array with JavaScript?
- How to convert an integer to a hexadecimal string in Python?
- How to convert an integer to a octal string in Python?
- How to convert string into float in JavaScript?
- How do I convert a string to a number in Python?

Advertisements