Arithmetic operators
+,-,*,/,%,+ +, --
+ +,-- divided into prefix form and suffix form
prefix form plus minus 1 in execution
The suffix form executes plus minus 1
Attention
+ number to connect two strings
as long as one of the + connected operands is a string type,JS automatically handles non-string data as String data.
the execution order of the JS code is left to right, so in the + connected expression, all occurrences of numeric data ( or can be automatically converted to numeric data) before the string data is encountered ) is still treated as a numeric value. To avoid this situation, we can spell an empty string before the expression
Instance
<! DOCTYPE html>
<meta charset= "Utf-8" >
<title></title>
<body>
<script type= "Text/javascript" >
examples of arithmetic operators
var i=3,j=8;
document.write (I+J);
document.write (' <br/> ');
document.write (I-J);
document.write (' <br/> ');
document.write (I*J);
document.write (' <br/> ');
document.write (i/j);
document.write (' <br/> ');
document.write (I%J);
document.write (' <br/> ');
document.write (3%-8);
document.write (' <br/> ');
document.write ( -3%8);
document.write (' <br/> ');
document.write ( -3%-8);
document.write (' <br/> ');
+ More Special
document.write (i+ ' 8 ');
document.write (' <br/> ');
document.write (' 2 ' + ' 8 ');
document.write (' <br/> ');
document.write (i+j+ ' 3king ');
document.write (' <br/> ');
document.write (' +i ');
var z= ' +i;
Alert (typeof z);
document.write (' <br/> ');
document.write (' +i+j+ ' 3king ');
document.write (' <br/> ');
self-increment decrement operator + +--
integer Support self-increment decrement operator
var num1=1;
alert (num1++);
alert (NUM1);
alert (++NUM1);
alert (--NUM1);
floating-point support self-increment decrement operator
num1=12.3;
alert (--NUM1);
Num1=true;
Num1=false;
alert (++NUM1);
alert (--NUM1);
The self-increment decrement operator is not supported for string types
num1= ' 3b ';
alert (++NUM1);
alert (--NUM1);
Null support for self-increment decrement operator
Num1=null;
alert (++NUM1);
alert (--NUM1);
num1=undefined;
alert (++NUM1);
</Script>
</body>
Operation Result:
original link:http://www.maiziedu.com/wiki/js/sum/
A detailed description of JavaScript arithmetic operators