Search
Document Center

# Operator

Last Updated: Feb 04, 2021

## Arithmetic operator

``var a = 10, b = 20;``// Addition operation``console.log(30 === a + b);``// Substraction operation``console.log(-10 === a - b);``// Multiplication operation``console.log(200 === a * b);``// Division operation``console.log(0.5 === a / b);``// Complementation operation``console.log(10 === a % b);``

The addition `+<`/> operator can be used for string concatenation.

``var a = 'hello', b = ' alipay';``// String concatenation``console.log('hello alipay' === a + b);``

## Comparison operator

``var a = 10, b = 20;``// Less than``console.log(true === (a < b));``// More than``console.log(false === (a > b));``// Less than or equal to``console.log(true === (a <= b));``// More than or equal to``console.log(false === (a >= b));``// Equal sign``console.log(false === (a == b));``// Not equal sign``console.log(true === (a != b));``// Equivalent sign``console.log(false === (a === b));``// Not equivalent sign``console.log(true === (a !== b));``

## Binary logical operator

``var a = 10, b = 20;``// AND``console.log(20 === (a && b));``// OR``console.log(10 === (a || b));``// NOT, negation operation``console.log(false === !a);``

## Bitwise operator

``var a = 10, b = 20;``// Left shift operation``console.log(80 === (a << 3));``// Unsigned right shift operation``console.log(2 === (a >> 2));``// Signed right shift operation``console.log(2 === (a >>> 2));``// AND operation``console.log(2 === (a & 3));``// XOR operation``console.log(9 === (a ^ 3));``// OR operation``console.log(11 === (a | 3));``

## Assignment operator

``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);``

## Unary operator

``var a = 10, b = 20;``// Auto increment operation``console.log(10 === a++);``console.log(12 === ++a);``// Auto decrement operation``console.log(12 === a--);``console.log(10 === --a);``// Positive value operation``console.log(10 === +a);``// Negative value operation``console.log(0-10 === -a);``// Not operation``console.log(-11 === ~a);``// Negation operation``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);``

## Ternary operator

``var a = 10, b = 20;``// Conditional operator``console.log(20 === (a >= 10 ? a + 10 : b + 10));``

## Comma operator

``var a = 10, b = 20;``// Comma operator``console.log(20 === (a, b));``

## Operator precedence

SJS operators have the same precedence as Javascript operators.