ECMAScript defines 5 arithmetic operators, plus, minus, multiply, divide, and modulo (take-up). If the value of the arithmetic operation is not numeric, then the background will first convert it to a numeric value (implicit conversion) using the number () transformation function.
One, addition
varbox = 1 + 2;//equals 3 varbox = 1 + NaN;//Nan, as long as one nan is Nan varbox = Infinity + Infinity;//Infinity varbox =-infinity +-infinity;//-infinity varbox = Infinity +-infinity;//Nan, positive infinity and negative infinity addition, etc. nan varbox = 100 + ' 100 ';//100100, String connector, string is not an addition varbox = ' Your age is: ' + 10 + 20;//your age is: 1020, converted to string varbox = 10 + 20 + ' is your age ';//30 is your age and has not been turned into a string varbox = ' Your age is: ' + (10 + 20);//your age is: 30, not converted into a string varbox = 10 + {}//10[object Object], the last type is a string type, and if there is toString () or valueOf () returns the value of the + + return number varBox =10+{toString:function(){ return100; }} alert (box);// the
Second, subtraction
varbox = 100-70;//equals varbox =-100-70//equals -170 varbox =-100--70//-30, generally written-100-(-70) relatively clear varbox = 1-nan;//Nan, as long as one nan is Nan varbox = infinity-infinity;//NaN varbox =-infinity--infinity;//NaN varbox = Infinity--infinity;//Infinity varbox =-infinity-infinity;//-infinity varbox = 100-true;//99,true turns into a value of 1 varbox = 100-";//100, ' turned into 0 results or varbox = 100-' 70 ';//30, ' 70 ' turns into a value of varbox = 100-NULL;//100,null turned 0. varbox =-' Lee ';//Nan,lee turned into NaN. varbox = 100-{};//NaN, if there is toString () or valueOf () returns 100-the value of the return number varbox = 100-{toString:function(){ return10; } }; alert (box);
Third, multiplication
varbox = 100 * 70;//7000 varbox = * NaN;//Nan, as long as there is a nan that is Nan varbox = Infinity * Infinity;//Infinity varbox =-infinity * Infinity;//-infinity varbox =-infinity *-infinity;//Infinity varbox = 100 *true;//100,true turns into a value of 1 varbox = 100 * ";//0, "turned 0." varbox = 100 *NULL;//0,null turned 0. varbox = * ' Lee ';//Nan,lee turned into NaN. varbox = 100 * {};//NaN, if there is toString () or valueOf () returns 100-the value of the return number
Iv. Division
varbox = 100/70;//1.42 .... varbox = 100/nan;//NaN varbox = infinity/infinity;//NaN varbox =-infinity/infinity;//NaN varbox =-infinity/-infinity;//NaN varbox = 100/true;//100,true turns into 1 . varbox = 100/';//Infinity, divide two numbers, the second number cannot be 0 varbox = 100/NULL;//Infinity, varbox = +/' Lee ';//NaN varbox = 100/{};//NaN, if there is toString () or valueOf () returns the value of 100/return number
Five, to find a model
varbox = 10 3;//1, the remainder is 1 varbox =% NaN;//NaN varbox = Infinity% Infinity;//NaN varbox =-infinity% Infinity;//NaN varbox =-infinity%-infinity;//NaN varbox = 100true;//0 varbox = 100 ';//NaN varbox = 100NULL;//NaN varbox =% ' Lee ';//NaN varbox = 100 {};//NaN, if there is toString () or valueOf () returns a value of 100 of the returned number
Arithmetic operators for JavaScript