javascript--Data type Conversions

Source: Internet
Author: User

In practical programming, a part of the data needs to be converted uniformly into a data type for processing, including converting to string types, converting to numbers, and system automatic data type conversions.

1. Converting to a string

  JavaScript is an object-based scripting language, and all data types can be considered objects. All objects have the toString () method.

2. Convert to Digital

  Only data with string literals (numbers, symbols, and decimal points in a string) can be converted in normal, other types return Nan (not a number)

A) Parsein ()

b) parsefloat ()

3. Automatic type conversion

  In the presence of different types of data, the system will handle the type of data according to different situations.

  A) numeric value + string: The value is converted to a string and then concatenated with the string;

b) Value-string: The string is converted to a numeric value and the difference between the two is calculated;

c) string + string: connection string;

d)-*/between strings: strings are converted to numeric values for calculation;

Automatic type conversion can cause errors in calculation results, for readability, casting (recommended), forcing type conversion methods:

A) Boolean (value)

b) Number (value)

c) String (value)

javascript--Data type Conversions

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.