JavaScript Data type conversions

Source: Internet
Author: User
Tags arithmetic operators

numeric types are automatically converted to strings when the data for a string, numeric type is additive.

When the IF condition is inside, the result is automatically converted to a Boolean type of data.

1 <script type= "Text/javascript" >2     var a = 1; 3     var b = ' 2 '; 4     Console.log (typeof(a+b));    //   string5 </script>
To force type conversions:
Conversion functions Meaning
Number () Forcing other types of data to be converted to numeric type
parseint () Forcing other types of data to be converted to integers
Parsefloar () Force other types of data to be converted to number type (decimal)
String () Forcing other types of data to be converted into strings
Boolean () Convert other types of data to Boolean

1 <script type= "Text/javascript" >2     varnull; 3     Console.log (parseint (Vone));    // NaN 4 </script>
JavaScript operator.

1. Arithmetic operators

1 <script type= "Text/javascript" >2     var a = ten; 3     var b = a++; 4     var c =--b; 5     var d = C + + + + +; 6     var e = d-----D; 7     Alert (e);    // 2 8 </script>

2. Assignment operators

=,+=,-=,*=,/=,%=

3. Comparison operators

>,<,==,===,!=,!===,>=,<=

4. Logical operators

&&,| |,!

5. Ternary operators

Condition ==true? True:false

1 <script type= "Text/javascript" >2     var a = ten; 3     var b = Ten; 4     A+b = = 20? Alert (' True '): Alert (' false '); 5 </script>

JavaScript process statements

Note: If you use else if the else if is in the middle there is a space. The For in () loop can iterate over an array, an object

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.