ToString Method
Returns the string representation of an object.
Objectname. toString ([radix]) parameter
Objectname
Required. The object to be represented by a string.
Radix
Optional. Specifies the hexadecimal format when the numeric value is converted to a string.
Description
The toString method is a member of all built-in JScript objects. Its operations depend on the object type:
Object operations
Array converts an Array element to a string. The result string is separated by commas and connected.
If the Boolean value is true, "true" is returned ". Otherwise, "false" is returned ".
Date returns the text representation of the Date.
Error returns a string containing the Error information.
Function returns a string in the following format. functionname is the name of the Function called toString:
Function functionname () {[native code]}
Number returns the text representation of a Number.
String returns the value of the String object.
By default, "[object objectname]" is returned, where objectname is the object type name.
Example
The following example shows how to use the toString method with the radix parameter. The Return Value of the function shown above is a Radix conversion table.
Copy codeThe Code is as follows:
Function CreateRadixTable (){
Var s, s1, s2, s3, x; // declare the variable.
S = "Hex Dec Bin \ n"; // create a header.
For (x = 0; x <16; x ++) // according to
{// Number Creation
Switch (x) // table size.
{// Set the space between columns.
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 hexadecimal, decimal, and binary.
S + = "" + x. toString (16) + s1 + x. toString (10)
S + = s2 + s3 + x. toString (2) + "\ n ";
}
Return (s); // return the entire radix table.
}