# operator
# Basic operators
Example code:
var a = 10, b = 20;
// Add-up operations
console.log(30 === a + b);
// Subtraction operations
console.log(-10 === a - b);
// Multiplying
console.log(200 === a * b);
// The division operation
console.log(0.5 === a / b);
// Savings calculation
console.log(10 === a % b);
- Addition operation (
+)Can also be used as a concatenation of character strings.
var a = '.w' , b = 'xs';
// Character string concatenation
console.log('.wxs' === a + b);
# One-dollar operators
Example code:
var a = 10, b = 20;
// Incremental calculation
console.log(10 === a++);
console.log(12 === ++a);
// Subtraction operations
console.log(12 === a--);
console.log(10 === --a);
// Positive timing calculation
console.log(10 === +a);
// Negative Numerical Operations
console.log(0-10 === -a);
// No calculation
console.log(-11 === ~a);
// Reverse operations
console.log(false === !a);
// Delete operation
console.log(true === delete a.fake);
// Void operation
console.log(undefined === void a);
// Typeof operation
console.log("number" === typeof a);
# Bit operator
Example code:
var a = 10, b = 20;
// The left-shifting operation
console.log(80 === (a << 3));
// Right-shifting operations with symbols
console.log(2 === (a >> 2));
// No symbol right-shift operation
console.log(2 === (a >>> 2));
// And Computing
console.log(2 === (a & 3));
// Variants or operations
console.log(9 === (a ^ 3));
// Or arithmetic
console.log(11 === (a | 3));
# Comparing Operators
Example code:
var a = 10, b = 20;
// Less than
console.log(true === (a < b));
// greater than
console.log(false === (a > b));
// Less than equals
console.log(true === (a <= b));
// More than equals
console.log(false === (a >= b));
# Equator operator
Example code:
var a = 10, b = 20;
// Equal sign
console.log(false === (a == b));
// Non-equivalent number
console.log(true === (a != b));
// Full Equator
console.log(false === (a === b));
// Incomplete equality
console.log(true === (a !== b));
# An assignment operator
Example code:
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);
# Binary logic operation
Example code:
var a = 10, b = 20;
// Logic and Reason
console.log(20 === (a && b));
// Logic or
console.log(10 === (a || b));
# Other operators
Example code:
var a = 10, b = 20;
//条件运算符
console.log(20 === (a >= 10 ? a + 10 : b + 10));
//逗号运算符
console.log(20 === (a, b));
# Operator precedence
| priority | operator | Introductions | Confectionality |
|---|---|---|---|
| 20 | (...) | brackets | n/a |
| 19 | ....... | Members visit | From left to right |
...[...] | Members visit | From left to right | |
...(...) | Function call | From left to right | |
| 17 | ...++ | Reverse increments | n/a |
...-- | Reverse decrease | n/a | |
| 16 | !... | Logic is not. | From right to left |
~... | None by location | From right to left | |
+... | One-dollar addition | From right to left | |
-... | One-dimensional reduction | From right to left | |
++... | Forward increments | From right to left | |
--... | Prediction diminished | From right to left | |
typeof... | typeof | From right to left | |
void... | void | From right to left | |
delete... | delete | From right to left | |
| 14 | ...*... | multiplication | From left to right |
.../... | division | From left to right | |
...%... | modulo | From left to right | |
| 13 | ...+... | addition | From left to right |
...-... | subtraction | From left to right | |
| 12 | ...<<... | Move left by position | From left to right |
...>>... | Move to the right by position | From left to right | |
...>>>... | No symbols move to the right | From left to right | |
| 11 | ...<... | Less than | From left to right |
...<=... | Less than equals | From left to right | |
...>... | greater than | From left to right | |
...>=... | More than equals | From left to right | |
| 10 | ...==... | Equal sign | From left to right |
...!=... | Non-equivalent number | From left to right | |
...===... | Full Equator | From left to right | |
...!==... | Incomplete equality | From left to right | |
| 9 | ...&... | By location and | From left to right |
| 8 | ...^... | Depending on location or | From left to right |
| 7 | ...|... | By position or | From left to right |
| 6 | ...&&... | Logic and Reason | From left to right |
| 5 | ...||... | Logic or | From left to right |
| 4 | ...?...:... | Conditional operator | From right to left |
| 3 | ...=... | An assignment value | From right to left |
...+=... | An assignment value | From right to left | |
...-=... | An assignment value | From right to left | |
...*=... | An assignment value | From right to left | |
.../=... | An assignment value | From right to left | |
...%=... | An assignment value | From right to left | |
...<<=... | An assignment value | From right to left | |
...>>=... | An assignment value | From right to left | |
...>>>=... | An assignment value | From right to left | |
...&=... | An assignment value | From right to left | |
...^=... | An assignment value | From right to left | |
...|=... | An assignment value | From right to left | |
| 0 | ...,... | comma | From left to right |