Converting Numbers to Strings

var n=16; var a = n.toString();  //a = 16 var b = n.toString(16); //b = 10

To convert a number to a string in JavaScript, create a variable with the numerical value if you don’t already have one and then call .toString(radix) on the number. The optional radix parameter specifies the base to use when converting the number. You can specify base 2 up to base 36.

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.