parseInt() function in JavaScript

HTMLJavascriptProgramming Scripts

The parseInt() function accepts two parameters one is a string representing a number and another is a number representing the radix and returns an integer of the given radix.

Syntax

Its Syntax is as follows

num.parseInt('4524', 8);

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var result = parseInt('4524', 8);
      document.write("Result: " + result);
   </script>
</body>
</html>

Output

Result: 2388

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var result1 = parseInt('4524', 8);
      document.write("Result: " + result1);
      document.write("<br>");
      var result2 = parseInt('4524', 10);
      document.write("Result: " + result2);
      document.write("<br>");
      var result3 = parseInt('4524', 16);
      document.write("Result: " + result3);
   </script>
</body>
</html>

Output

Result: 2388
Result: 4524
Result: 17700
raja
Published on 30-Oct-2018 07:09:36
Advertisements