Cast casting

ParseInt, parseFloat, toString, etc. (The second argument to parseInt and parseFloat is the base to convert to)


Implicit type conversion

If, logical operation, ==, + concatenate string

Here’s more on if, logical operations, ==

if

If truly judges truly services variable and Services variable, then the question becomes, what is TRULY service variable and what is truly service variable?

Suppose there is a variable a:

If!!!!! A === true represents the truly variable

If!!!!! A === false is represented as a Service variable

Services variable has: 0 false ‘[empty string]’ null undefined NaN Everything else is truly variable


Logical operations

&& a full false:

  1. Will return the left-hand expression immediately if the left-hand expression is a service variable
    console.log(null && 0);    // null
Copy the code
  1. The left-hand expression is the TRULY variable and the right-hand expression is the Services variable, so the right-hand expression is returned
    console.log(1 && NaN);    // NaN
Copy the code
  1. Both left and right are TRULY variables, return the right-hand expression
    console.log("yes" && 1);    / / 1
Copy the code

| | a true whole true:

  1. The left-hand expression is the TRULY variable, and the left-hand expression is returned immediately
    console.log("YesYes" || 1);    // YesYes
Copy the code
  1. The left-hand expression is a Service variable, but the right-hand expression is a TRULY variable and the right-hand expression is returned
    console.log(NaN || 123);    / / 123
Copy the code
  1. Services variable on the left and right, return the right-hand expression
    console.log(' ' || 0);    / / 0
Copy the code

= = and = = =

Something that uses the == sign for comparison will do an implicit conversion first, service variable will change to false, truly variable will change to false and value comparison will take place, whereas something that uses the === sign will compare types first and return false if the types are different and continue to compare values if the types are the same, Value types compare values directly, and reference types compare memory addresses.

So when do you use second class and when do you use third class? === = (XXX) === (XXX) === (XXX) === (XXX))

null == xxx ---> null === xxx || undefined === xxx