Implicit conversion and casts

Implicit conversion:
   Scene - mathematical operators: + - * /
  Rules:
    +: when the character appears on either side, "+" will be converted into numeric type character type, representative of the splice case +
    -, *, /: emergence when purely numeric characters, converted into a numerical type of treatment, non-numeric type occurs, there will be "NaN"

  Scene - relational operators:> <!> = <= = == ===
  rule:
    when only one side is purely numeric characters, converted into a numerical comparison
    , when both sides of all numeric characters, the string comparison will follow Comparative rule (bit-wise comparison, the results obtained, the comparison stops)
    ==: if the character type converted to numeric types, the comparison is a value
    ===: if a character is not the type conversion, comparing the values and data types, congruent

  Scene --if statement:
  Rules:

    0, "", null, undefined, NaN if in the () are converted to false


Cast:
   Character transfer value:
    parseInt (): from left to right conversion, you can turn turn, can not be transferred stop; if you can not turn the first direct NaN; does not recognize decimal point.
    parseFloat (): equivalent to the parseInt, while the decimal point may be identified
    Math.round (): Conversion strictly, any non-numeric characters are not allowed, otherwise NaN3; rounded to the nearest integer
    Number (): Conversion strictly, does not allow any non- numeric characters, or NaN3; direct conversion
    -, *, /: using a mathematical operator implicit conversion, the values into character

  Numerical character turn:
    toString (): to convert into a direct numerical character
    toFixed (): direct conversion parameter decimal place reserved
    +: using a mathematical operator implicit conversion, a null character + is connected
to other types of conversions:

  Use +, -, *, / p true, false, null conversion can be obtained, true is 1, false is 0, null 0

Guess you like

Origin www.cnblogs.com/maozo/p/11737154.html