| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | f1_keywords | dev_langs | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toString Method (Object) (JavaScript) | Microsoft Docs |
01/18/2017 |
windows-client-threshold |
|
language-reference |
|
|
|
c4ae9da2-60c9-486f-b00a-9df03fda4a35 |
15 |
mikejo5000 |
mikejo |
ghogen |
Returns a string representation of an object.
objectname.toString([radix])
objectname
Required. An object for which a string representation is sought.
radix
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 [!INCLUDEjavascript] objects. How it behaves depends on the object type:
| Object | Behavior |
|---|---|
| Array | Elements of an Array are converted to strings. The resulting strings are concatenated, separated by commas. |
| Boolean | If the Boolean value is true, returns "true". Otherwise, returns "false". |
| Date | Returns the textual representation of the date. |
| Error | Returns a string containing the associated error message. |
| Function | Returns a string of the following form, where functionname is the name of the function whose toString method was called:function functionname( ) { [native code] } |
| Number | Returns the textual representation of the number. |
| String | Returns the value of the String object. |
| Default | 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";
}
return(s);
} [!INCLUDEjsv2]
Applies To: Array Object| Boolean Object| Date Object| Error Object| Function Object| Number Object| Object Object| String Object