Number toString()

toString() method optionally accepts a single argument indicating the radix:

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
        var num = 10; 
        document.writeln(num.toString()); //"10" 
        document.writeln(num.toString(2)); //"1010" 
        document.writeln(num.toString(8)); //"12" 
        document.writeln(num.toString(10)); //"10" 
        document.writeln(num.toString(16)); //"a" 
       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo

The following code is using the Number.toString method to do the conversion.

 
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<body>
  <script type="text/javascript">
    var myData1 = (5).toString() + String(5);
    document.writeln("Result: " + myData1);
  </script>
</body>
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    Essential Types  

Number:
  1. The Number Type
  2. Number toExponential()
  3. Number toFixed()
  4. Number toPrecision()
  5. Number toString()
  6. Number valueOf()
  7. Converting Strings to Numbers
  8. typeof and instanceof for Number objects and primitive values