MDN wants to talk to developers like you:

Number.toString Redirect 1


The toString() method returns a string representing the specified Number object.




An integer between 2 and 36 specifying the base to use for representing numeric values.



If toString() is given a radix not between 2 and 36, a RangeError is thrown.


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 radixes above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), a through f are used.

If the radix is not specified, the preferred radix is assumed to be 10.

If the number is negative, the sign is preserved. Especially if the radix is 2, it's returning the binary (zeros and ones) of the number preceeded by a - sign but the two's complement.


var count = 10;

print( count.toString() );   // displays "10"
print( (17).toString() );    // displays "17"

var x = 6;

print( x.toString(2) );      // displays "110"
print( (254).toString(16) ); // displays "fe"

print( (-10).toString(2) );  // displays "-1010"
print( (-0xff).toString(2) );// displays "-11111111"


Specification Status Comment
ECMAScript 1st Edition. Implemented in JavaScript 1.1 Standard Initial definition.
ECMAScript Language Specification 5.1th Edition (ECMA-262) Standard  
ECMAScript Language Specification 6th Edition (ECMA-262) Draft  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See Also

Document Tags and Contributors

 Last updated by: Sheppy,