THE WORLD'S LARGEST WEB DEVELOPER SITE

JavaScript Number toString() Method

❮ JavaScript Number Reference

Example

Convert a number to a string:

var num = 15;
var n = num.toString();
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

The toString() method converts a number to a string.


Browser Support

Method
toString() Yes Yes Yes Yes Yes

Syntax

number.toString(radix)

Parameter Values

Parameter Description
radix Optional. Which base to use for representing a numeric value. Must be an integer between 2 and 36.
  • 2 - The number will show as a binary value
  • 8 - The number will show as an octal value
  • 16 - The number will show as an hexadecimal value


Technical Details

Return Value: A String, representing a number
JavaScript Version: ECMAScript 1

More Examples

Example

Convert a number to a string, using different bases:

var num = 15;
var a = num.toString();
var b = num.toString(2);
var c = num.toString(8);
var d = num.toString(16);
Try it Yourself »

❮ JavaScript Number Reference