JavaScript Number.prototype.toString() example. The Number object overrides the toString() method of the Object object. (It does not inherit Object.prototype.toString()). For Number objects, the toString() method returns a string representation of the object in the specified radix.
The toString() method parses its first argument, and attempts to return a string representation in the specified radix (base). For radices above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), a through f are used.
Syntax
1 | numObj.toString([radix]) |
Return value
A string representing the specified Number object.
Javascript toString() Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 | let count = 10 console.log(count.toString()) // displays '10' console.log((17).toString()) // displays '17' console.log((17.2).toString()) // displays '17.2' let x = 6 console.log(x.toString(2)) // displays '110' console.log((254).toString(16)) // displays 'fe' console.log((-10).toString(2)) // displays '-1010' console.log((-0xff).toString(2)) // displays '-11111111' |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.