toString

Returns a string representing the specified object.

Applies to

Number

Syntax

toString()
toString(radix)I I

Parameters

radix

(Optional) An integer between 2 and 16 specifying the base to use for representing numeric values.

Description

Every object has a toString method that is automatically called when it is to be represented as a text value or when an object is referred to in a string concatenation.

You can use toString within your own code to convert an object into a string, and you can create your own function to be called in place of the default toString method.

You can use toString on numeric values, but not on numeric heliterals:

// The next two lines are valid
var howMany=10
 ("howMany.toString() is " + howMany.toString() )
// The next line causes an error
 ("45.toString() is " + 45.toString() )

For information on defining your own toString method, see the Object.toString method.