var a = 10, b = 20;// Additionconsole.log(30 === a + b);// Subtractionconsole.log(-10 === a - b);// Multiplicationconsole.log(200 === a * b);// Divisionconsole.log(0.5 === a / b);// Complementationconsole.log(10 === a % b);
var a = '.w' , b = 'xs';// String concatenationconsole.log('.wxs' === a + b);
var a = 10, b = 20;// Auto incrementconsole.log(10 === a++);console.log(12 === ++a);// Auto decrementconsole.log(12 === a--);console.log(10 === --a);// Positive valueconsole.log(10 === +a);// Negative valueconsole.log(0-10 === -a);// Notconsole.log(-11 === ~a);// Negateconsole.log(false === !a);// Deleteconsole.log(true === delete a.fake);// Voidconsole.log(undefined === void a);// Typeofconsole.log("number" === typeof a);
var a = 10, b = 20;// Left shiftconsole.log(80 === (a << 3));// Unsigned right shiftconsole.log(2 === (a >> 2));// Signed right shiftconsole.log(2 === (a >>> 2));// ANDconsole.log(2 === (a & 3));// XORconsole.log(9 === (a ^ 3));// ORconsole.log(11 === (a | 3));
var a = 10, b = 20;// Less thanconsole.log(true === (a < b));// Greater thanconsole.log(false === (a > b));// Less than or equal toconsole.log(true === (a <= b));// Greater than or equal toconsole.log(false === (a >= b));
var a = 10, b = 20;// Equal signconsole.log(false === (a == b));// Not equal signconsole.log(true === (a != b));// Equivalent signconsole.log(false === (a === b));// Not equivalent signconsole.log(true === (a !== b));
var a = 10;a = 10; a *= 10;console.log(100 === a);a = 10; a /= 5;console.log(2 === a);a = 10; a %= 7;console.log(3 === a);a = 10; a += 5;console.log(15 === a);a = 10; a -= 11;console.log(-1 === a);a = 10; a <<= 10;console.log(10240 === a);a = 10; a >>= 2;console.log(2 === a);a = 10; a >>>= 2;console.log(2 === a);a = 10; a &= 3;console.log(2 === a);a = 10; a ^= 3;console.log(9 === a);a = 10; a |= 3;console.log(11 === a);
var a = 10, b = 20;// Logical ANDconsole.log(20 === (a && b));// Logical ORconsole.log(10 === (a || b));
var a = 10, b = 20;//Conditional operatorconsole.log(20 === (a >= 10 ? a + 10 : b + 10));//Comma operatorconsole.log(20 === (a, b));
Priority | Operator | Description | Associativity |
20 | ( ... ) | Brackets | n/a |
19 | ... . ... | Member access | Left to right |
| ... [ ... ] | Member access | Left to right |
| ... ( ... ) | Function call | Left to right |
17 | ... ++ | Postfix increment | n/a |
| ... -- | Postfix decrement | n/a |
16 | ! ... | Logical not | Right to left |
| ~ ... | Bitwise not | Right to left |
| + ... | Unary addition | Right to left |
| - ... | Unary subtraction | Right to left |
| ++ ... | Prefix increment | Right to left |
| -- ... | Prefix decrement | Right to left |
| typeof ... | typeof | Right to left |
| void ... | void | Right to left |
| delete ... | delete | Right to left |
14 | ... * ... | Multiplication | Left to right |
| ... / ... | Division | Left to right |
| ... % ... | Modulo | Left to right |
13 | ... + ... | Addition | Left to right |
| ... - ... | Subtraction | left to right |
12 | ... << ... | Bitwise left shift | Left to right |
| ... >> ... | Bitwise right shift | Left to right |
| ... >>> ... | Unsigned right shift | Left to right |
11 | ... < ... | Less than | Left to right |
| ... <= ... | Less than or equal to | Left to right |
| ... > ... | Greater than | Left to right |
| ... >= ... | Greater than or equal to | Left to right |
10 | ... == ... | Equal sign | Left to right |
| ... != ... | Not equal sign | Left to right |
| ... === ... | Equivalent sign | Left to right |
| ... !== ... | Not equivalent sign | Left to right |
9 | ... & ... | Bitwise AND | Left to right |
8 | ... ^ ... | Bitwise XOR | Left to right |
7 | ... | ... | Bitwise OR | Left to right |
6 | ... && ... | Logical AND | Left to right |
5 | ... || ... | Local OR | Left to right |
4 | ... ? ... : ... | Conditional operator | Left to right |
3 | ... = ... | Value assignment | Left to right |
| ... += ... | Value assignment | Left to right |
| ... -= ... | Value assignment | Left to right |
| ... *= ... | Value assignment | Left to right |
| ... /= ... | Value assignment | Left to right |
| ... %= ... | Value assignment | Left to right |
| ... <<= ... | Value assignment | Left to right |
| ... >>= ... | Value assignment | Left to right |
| ... >>>= ... | Value assignment | Left to right |
| ... &= ... | Value assignment | Left to right |
| ... ^= ... | Value assignment | Left to right |
| ... |= ... | Value assignment | Right to left |
0 | ... , ... | Comma | Left to right |
Was this page helpful?