The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

toString Method (Object) (JavaScript)

Returns a string representation of an object.



Required. An object for which a string representation is sought.


Optional. Specifies a radix for converting numeric values to strings. This value is only used for numbers.

The toString method is a member of all built-in JavaScript objects. How it behaves depends on the object type:




Elements of an Array are converted to strings. The resulting strings are concatenated, separated by commas.


If the Boolean value is true, returns "true". Otherwise, returns "false".


Returns the textual representation of the date.


Returns a string containing the associated error message.


Returns a string of the following form, where functionname is the name of the function whose toString method was called:

function functionname( ) { [native code] }


Returns the textual representation of the number.


Returns the value of the String object.


Returns "[object objectname]", where objectname is the name of the object type.

The following example illustrates the use of the toString method with a radix argument. The return value of function shown below is a Radix conversion table.

function CreateRadixTable (){
   var s = "";

   // Create table heading.
   s += "Hex  Dec  Bin \n";

   for (x = 0; x < 16; x++)
      s += "   ";

      // Convert to hexidecimal.
      s += x.toString(16);
      s += "     ";
      if (x < 10) s += "  ";

      // Convert to decimal.
      s += x.toString(10);
      s += "     ";

      // Convert to binary.
      s += x.toString(2);
      s += "\n";


Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

Applies To: Array Object (JavaScript)| Boolean Object (JavaScript)| Date Object (JavaScript)| Error Object (JavaScript)| Function Object (JavaScript)| Number Object (JavaScript)| Object Object (JavaScript)| String Object (JavaScript)

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft