A few words about tostring () and string ()

Source: Internet
Author: User

We all know that there are two methods to convert a value into a string. One is to use the tostring () method, and the other is to use the transformation function string (). However, some details are worth noting.

1. Almost every value has the tostring () method, which indicates that some values do not exist, that is, null and undefined.

2. You can use tostring () to return a copy of the string.

3. The tostring () method can pass a parameter, indicating the base number of the value.

For example, var t = 8;

T. tostring (2); // 1000

The default value is 10. It should be noted that the tostring () parameter set for non-numeric values (Boolean, String, etc.) is invalid,

For example, var t = "8 ";

T. tostring (2); // 8, which may be considered as 1000

4. You can use the string () method for any value. The process is as follows:

First, if the value has the tostring () method, use this method (No parameter ).

Second, there is no tostring () method for this value, that is, null returns "null", undefined returns "undefined"

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.