Operator

Arithmetic Operator

copy
var a = 10, b = 20;
// addition operation
console.log(30 === a + b);
// subtraction 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.

copy
var a = 'hello', b = ' world';
// string concatenation
console.log('hello world' === a + b);

Comparison Operator

copy
var a = 10, b = 20;

// less than
console.log(true === (a < b));
// greater than
console.log(false === (a > b));
// less than or equal to
console.log(true === (a <= b));
// greater than or equal to
console.log(false === (a >= b));
// equal sign
console.log(false === (a == b));
// unequal sign
console.log(true === (a != b));
// all equal sign
console.log(false === (a === b));
// not all equal sign
console.log(true === (a !== b));

Binary Logical Operators

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

Bit Operator

copy
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

copy
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

copy
var a = 10, b = 20;
// increment operator
console.log(10 === a++);
console.log(12 === ++a);
// decrement operator
console.log(12 === a--);
console.log(10 === --a);
// positive operation
console.log(10 === +a);
// negative operation
console.log(0-10 === -a);
// not operation
console.log(-11 === ~a);
// inverse operation
console.log(false === !a);
// delete operation
console.log(true === delete a.fake);
// void operation
console.log(undefined === void a);
// type of operation
console.log("number" === typeof a);

Ternary Operator

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

Comma Operator

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

Operator Priority

The priority of SJS operators is the same as in the Javascript.