toString Method (JScript 5.6)
Returns a string representation of an object.
objectname.toString([radix])
Arguments
- 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.
Remarks
The toString method is a member of all built-in JScript 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 " |
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:
|
Number |
Returns the textual representation of the number. |
String |
Returns the value of the String object. |
Default |
Returns |
Example
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, s1, s2, s3, x; //Declare variables.
s = "Hex Dec Bin \n"; //Create table heading.
for (x = 0; x < 16; x++) //Establish size of table
{ // in terms of number of
switch(x) // values shown.
{ //Set intercolumn spacing.
case 0 :
s1 = " ";
s2 = " ";
s3 = " ";
break;
case 1 :
s1 = " ";
s2 = " ";
s3 = " ";
break;
case 2 :
s3 = " ";
break;
case 3 :
s3 = " ";
break;
case 4 :
s3 = " ";
break;
case 5 :
s3 = " ";
break;
case 6 :
s3 = " ";
break;
case 7 :
s3 = " ";
break;
case 8 :
s3 = "" ;
break;
case 9 :
s3 = "";
break;
default:
s1 = " ";
s2 = "";
s3 = " ";
} //Convert to hex, decimal & binary.
s += " " + x.toString(16) + s1 + x.toString(10)
s += s2 + s3 + x.toString(2)+ "\n";
}
return(s); //Return entire radix table.
}
Requirements
Applies To: Array Object (JScript 5.6)| Boolean Object (JScript 5.6)| Date Object (JScript 5.6)| Error Object (JScript 5.6)| Function Object (JScript 5.6)| Number Object (JScript 5.6)| Object Object (JScript 5.6)| String Object (JScript 5.6)