1 Example(s) of Javascript toString function

Description :

JavaScript toString function is used to convert value to string and it has an optional parameter which base to use for representing a numeric value and this must be an integer between 2 and 36. See the code snippet:

Javascript toString function Example - 1
<!DOCTYPE html>
<title>Welcome to LearnKode - A code learning platform</title>
<button onclick="formatNumber()">Display the formatted numbers</button>

<p id="sample"></p>

function formatNumber() {
    var num = 17;
    var a = num.toString();
    var b = num.toString(3);
    var c = num.toString(5);
    var d = num.toString(16);

    var result = a + "<br>" + b + "<br>" + c + "<br>" + d;