1.加法
var box=1+2 //3 var box=1+NaN //NaN,有一个为NaN就为NaN var box=Infinity+Infinity //Infinity var box=-Infinity + -Infinity //-Infinity var box=Infinity + -Infinity //NaN,正无穷和负无穷相加为NaN var box=100+ ‘100‘; //100100,有一个为字符串相加为字符串拼接 var box=‘你的年龄是‘+10+20; //你的年龄是1020,后面的整形已转换成字符串 var box=‘你的年龄是‘+(10+20); //你的年龄是30,后面的整形先相加在转换吃字符串 var box=10+20+‘是你的年龄‘; //30是你的年龄,先相加,在转换成字符串 var box=10+对象; //10[object Object],如果有toString()或valueOf()则返回10+返回的值
注:++和--一样
var box=1; box++; //box=2,box=box+1 ++box; //box=3,box=box+1 var age=box++ //box=4;age=3,先赋值在运算 var pox=++box //pox=5;box=5,先运算在赋值
2.减法
var box=100-70; //30 var box=-100-70; //-170 var box=-100--70; //-30 var box=-100-NaN //NaN var box=Infinity-Infinity //NaN var box=-Infinity--Infinity //NaN var box=Infinity--Infinity //Infinity var box=-Infinity-Infinity //-Infinity var box=100-true; //99,true转换成数值为1 var box=100-‘‘; //100,‘‘转换为0
3.除法
var box=100/70 ///1.42.... var box=100/NaN ///NaN var box=Infinity/Infinity ///NaN var box=-Infinity/Infinity ///NaN var box=-Infinity/-Infinity ///NaN var box=100/true ///100,true转换成1 var box=100/‘‘ /// Infinity var box=100/null ///Infinity var box=100/‘lee‘ ///NaN var box=100/对象 ///NaN ,如果有toString()或valueOf(),返回10/返回值
4.求模
var box=10%3; //1,余数为1 var box=100%NaN; //NaN var box=Infinity%Infinity //NaN var box=100%true //0 var box=100%‘‘ //NaN var box=100%null //NaN