JavaScript type Conversion Use method _ Basics

Source: Internet
Author: User

(i) Convert to string

Copy Code code as follows:

X + ""
ToString ()
String ()

A function is converted to a string that typically outputs a function body, but can override its ToString method

(ii) conversion to digital

Copy Code code as follows:

parseint (), parsefloat ()

Use number (), do not add new before, so it is converted to an object.

Participate in mathematical operations (except addition)

+ X: Note that this is not an addition

(iii) conversion to Boolean value

Automatic conversion: If statements, | |,&&,! and other logical judgments will automatically convert an expression to a Boolean value in the environment

Cast: Use!!, use Boolean (), do not add new before, so it is converted to an object.

(iv) Conversion to object

Direct new+ Object Name

(v) Summary

All types have: object names (variables to be converted) conversion methods, as well as some of their own independent skills.

JS type conversion, you can refer to the following figure:

Related Article

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.