Js data toString Method

Source: Internet
Author: User

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.
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.