parseInt-2

 

In this example, We will sum the value of two variable a and b and show in paragraph inner html, See code snippet:

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <button onclick="convertToInt()">Parse the string to integer</button> <p id="sample"></p> <script> function convertToInt() { var a = parseInt("10"); var b = parseInt("10.00"); var result = a + b; document.getElementById("sample").innerHTML = result; } </script> </body> </html>
Output