Javascript data type conversion

Source: Internet
Author: User

Javascript has two data types:

(1) converting the entire value from one type to another (called Basic data type conversion)

(2) extract another type of value from one value and complete the conversion

 

Three methods for converting basic data types:

1. Convert to string type: string (); for example, the result of string (678) is "678"
2. Convert to numeric type: Number (); for example, the result of number ("678") is 678.
3. Convert to boolean: Boolean (); for example, Boolean ("AAA") returns true

 

How to extract another type of value from one value:

1. Extract the integer parseint () in the string. For example, the result of parseint ("123 Zhang") is 123.
2. Extract the floating point: parsefloat () in the string. For example, the result of parsefloat ("0.55 Zhang") is 0.55.
3. Execute a javascript stringCode: Eval (); example: Zhang = eval ("1 + 1") Result: Zhang = 2

Note: Number and string functions are special functions. In the JS engine, they will automatically determine whether they are called as constructors or normal calls. Therefore, they can use the new keyword, it can also be called directly as a function.

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.