JavaScript has two conversion methods for data types:
(i) converting an entire value from one type to another (called a basic data type conversion)
(ii) Extract the value of another type from one value and complete the conversion work
Three ways to convert basic data types:
1. Convert to Character type: String (); Example: The result of String (678) is "678"
2. Convert to Numeric type: number (); Example: The result of number ("678") is 678
3. Convert to Boolean: Boolean (); Example: Boolean ("AAA") results are true
The method of extracting a value from a value of another type:
1. Extract the integer in the string: parseint (); Example: The result of parseint ("123zhang") is 123
2. Extract the floating-point number in the string: parsefloat (); Example: The result of parsefloat ("0.55zhang") is 0.55
3. Execute a section of JavaScript code represented by a string: eval (); Example: The result of Zhang=eval ("1+1") zhang=2
Note: The number, String function is a special function, in the JS engine, he will automatically judge whether it is a constructor call or a normal call, so you can use the New keyword, can also be called as a function directly.
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.