Why 1 + + "2" = 3?

> 1+ +"2"
< 3

how does solving this code work? What is the role of spaces?

in addition, what is the principle of the process of solving false==null why it is false,?

Thank you ~

Mar.25,2021

  1. + "2" transforms to 2
  2. null==undefined, they only have this kind of relationship, which is different from the others.

keyword implicit type conversion .


clipboard.png

clipboard.png


+ "2" = > 2 / / A way to convert a string into a number, and then 1 / 2 / 3
as for false==null, you'd better look at the basics


implicit type conversion. You can check out the "JavaScript you don't know" series


  1. spaces are converted to 0;
    '2' is converted to 2.
  2. when comparing equality, Boolean operands are first converted to numeric values-- false is converted to zero, true is converted to 1;
    null and undefined are not converted to any other values when comparing equality. Null = = undefined returns true, but null = undefined returns false
Menu