1 算数运算

  1. //算数运算现将值自动转换成number类型在做计算(加法除外)
  2. console.log("3"-2);//1
  3. var a = 2+true;
  4. console.log(a);//3
  5. var b="hello"-1;
  6. console(b);//NaN
  7. //加法运算时有字符串则为字符串拼接
  8. console.log("12"+3);//123
  9. console.log(true+"123");//true123

2 比较运算

现将两边值转为number,再比较
NaN和任何值做比较,结果都为NaN

  1. var a=true;
  2. var b="10";
  3. var c="hello";
  4. console.log(a>b); // Number(a)>Number(b) 1>10 false
  5. console.log(a>c); // Number(a)>Number(c) 1>NaN false
  1. console.log(null==undefined) //true
  2. console.log(null==false) //false
  3. console.log(undefined==false) //false
  4. console.log(Number(null)) //0