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:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<button onclick="formatNumber()">Display the formatted numbers</button>
<p id="sample"></p>
<script>
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;
document.getElementById("sample").innerHTML=result;
}
</script>
</body>
</html>