Syntax error What is the role of parseInt() method in JavaScript?

What is the role of parseInt() method in JavaScript?



Use the parseInt() method in JavaScript to return an integer after parsing a string. You can also set the numeral system as a second parameter.

Example

You can try to run the following code to learn how to work with parseFloat() method in JavaScript.

<!DOCTYPE html>
<html>
   <body>
      <script>
         var val1 = parseInt("20.50");
         var val2 = parseInt("30 minutes");
         var val3 = parseInt("20",16);
         
         document.write(val1);
         document.write("<br>"+val2);
         document.write("<br>"+val3);
      </script>
   </body>
</html>
Updated on: 2020-05-23T11:04:04+05:30

247 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements