This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.



Returns a string representation of an object.


objectname.toString([ radix ])
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 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";



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

ArrayElements of an Array are converted to strings. The resulting strings are concatenated, separated by commas.
BooleanIf the Boolean value is true , returns " true ". Otherwise, returns " false ".
DateReturns the textual representation of the date.
ErrorReturns a string containing the associated error message.
FunctionReturns a string of the following form, where functionname is the name of the function whose toString method was called:Copy Code function functionname( ) { [native code] }
NumberReturns the textual representation of the number.
StringReturns the value of the String object.
DefaultReturns "[object objectname]" , where objectname is the name of the object type.

See also

Other articles


  • Microsoft Developer Network: Article