ECMAScript操作符
1.0、参考
1.1、算数运算符 
运算符运算说明示例
+
a + b
加法
var x = 2;
var y = x + 3;
字符串连接
var s = 'abc' + '123';
//s = 'abc123'
+a
取正
var x = 2;
var y = +x;
-
a - b
减法
var x = 2;
var y = x - 3;
-a
取相反数
var x = 2;
var y = -x;
*
a * b
乘法
var x = 2;
var y = x * 3;
**
a ** b
密方
var x = 2;
var y = x ** 3;
/
a / b
除法
var x = 2;
var y = x / 3;
%
a % b
取余
var x = 2;
var y = x % 3;
++
a++
后自增
var x = 2;
var y = x++;
++a
先自增
var x = 2;
var y = ++x;
--
a--
后自减
var x = 2;
var y = x--;
--a
先自减
var x = 2;
var y = --x;
1.2、位运算符 
运算符运算说明示例
&
a & b
按位与
var x = 2;
var y = x & 3;
|
a | b
按位或
var x = 2;
var y = x | 3;
^
a ^ b
按位异或
var x = 2;
var y = x ^ 3;
~
~ a
按位取反
var x = 2;
var y = ~ x;
<<
a << b
左移b
var x = 2;
x <<= 3;
>>
a >> b
右移b
符号位不移动
var x = 2;
x >>= 3;
>>>
a >>> b
右移b
符号位也移动
var x = 2;
x >>>= 3;
1.3、赋值运算符 
运算符运算相当于示例
=
var a = VALUE
var x = 2;
let y = x + 3;
+=
a += b
a = a + b
var x = 2;
x += 3;
-=
a -= b
a = a - b
var x = 2;
x -= 3;
*=
a *= b
a = a * b
var x = 2;
x *= 3;
**=
a **= b
a = a ** b
var x = 2;
x **= 3;
/=
a /= b
a = a / b
var x = 2;
x /= 3;
%=
a %= b
a = a % b
var x = 2;
x %= 3;
<<=
a <<= b
a = a << b
var x = 2;
x <<= 3;
>>=
a >>= b
a = a >> b
var x = 2;
x >>= 3;
>>>=
a >>>= b
a = a >>> b
var x = 2;
x >>>= 3;
1.4、关系运算符 
运算符运算说明示例
==
a == b
只要等于即可,不管类型是否相同
1 == true  //true
0 == false //true
0 == '0'   //true
===
a === b
不仅相等,类型也要相同
1 === true  //false
0 === false //false
0 === '0'   //false
!=
a != b
只要不等于即可
1 != true  //false
0 != false //false
0 != '0'   //false
!==
a !== b
只要类型有一个不相等,就算不相等
1 !== true  //true
0 !== false //true
0 !== '0'   //true
<
a < b
小于
1 < 2    //true
'0' < 1  //true
<=
a <= b
小于或等于
2 <= 2    //true
'2' <= 2  //true
>
a > b
大于
1 > 2    //false
'0' > 1  //false
>=
a >= b
大于或等于
2 >= 2    //true
'2' >= 2  //true
1.5、逻辑运算符 
运算符运算说明示例
&&
a && b
逻辑与
null && true  //null
undifined && true //undefined
0 && true   //0
'' && true   //''
||
a || b
逻辑或
null     || console.log('xx') //xx
undefined || console.log('xx') //xx
0         || console.log('xx') //xx
''        || console.log('xx') //xx
false     || console.log('xx') //xx
!
!a
逻辑非
!null     && console.log('xx') //xx
!undefined && console.log('xx') //xx
!0         && console.log('xx') //xx
!''        && console.log('xx') //xx
!false     && console.log('xx') //xx
1.6、条件运算符 

语法:

condition ? expression1 : expression2

示例:

var event = window.event ? window.event : e
1.7、其他运算符
运算符运算说明示例
typeof
typeof a
计算类型,返回类型字符串
typeof null     //object
typeof undifined //undefined
typeof 0         //number
typeof ''        //string
typeof true      //boolean
typeof eval      //function
typeof Object    //function
typeof Array     //function
typeof Boolean   //function
typeof Number    //function
instanceof
a instanceof b
判断a是否是b的实例
null instanceof Object //false
void
void(a)
得到undefined
<a href="javascript:void(window.open('about:blank'))">open</a>
new
new constructor()
创建对象
var date = new Date();
delete
delete(a)
删除变量或者对象的属性
var x = 5;
delete x
in
index in Array
attr in Object
判断给定的字符串是否为对象的属性
'PI' in Math && console.log(Math.PI)