JavaScript review--javascript data type implicit conversion

Source: Internet
Author: User

The JavaScript data type is implicitly converted.
One, the function class
IsNaN ()
The function implicitly converts the number () to a parameter and returns true if the conversion is unsuccessful.
Alert ()
The content of the output is implicitly converted to a string.

Two, the operator class.
1, arithmetic operator.
- * / %
If the operand is not a numeric value, the number () function is called implicitly. Follow the conversion rules for this function.
If the conversion is unsuccessful, the entire expression returns Nan.
+
If the operands are numeric, then add them.
Any data type and string additions are implicitly called by their ToString () method, and then return the result of their concatenation.
If the operands are all Boolean, then the number () conversion, false to 0,true 1, is added.

The operands of

    2, relational operators
       relational operators can be of any type and will be implicitly converted if the operand is not a numeric type.
          (1) The result of his operation is that the Boolean value
   (2) is a string, He would first convert to ASCII and then compare to size. The
   (3) is a numeric value when he compares normally.
          (4) when a string and the other is a numeric value, he attempts to convert the string into a numeric type and then compare it.
      If it cannot be converted to a numeric type, Nan (not a number) is returned, and a false is returned.
          (5) undefined null
   (6) If two are numeric strings, Then they will only compare the first one.
   (7) If a value is compared to a Boolean value, the Boolean value is converted to a numeric value and then compared, true to 1,false is 0
, and the equal operator.
     A. = Only compares values for equality.
      (1). When comparing strings, compare their ASCII codes for equality.
      (2). When comparing two values, compare their values for equality.
      (3). When comparing functions, determine whether their positions are equal.
     B = = = To compare whether their values are equal, and whether the types are equal.
 

Four, statement class
if (expression) {
}else{
}

Ternary operators
Format: var variable =boolean experssion? Truth: False value
while () {}
The expression in the IF statement and the ternary expression implicitly calls the Boolean function, which is converted to the corresponding Boolean value according to the conversion rules of the function.

JavaScript review--javascript data type implicit conversion

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.