- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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>
Advertisements