Operators
List the most common operators in Javascript
Assignment operators
let a = 1; // simple assign
a += 2; // same as a = a + 2
a -= 2; // same as a = a - 2
a *= 2; // same as a = a * 2
a /= 2; // same as a = a / 2
a **= 3; // same as a = a * a * (exponent)
a %= 2; // same as a = a % 2 (modulus)
Arithmatic operators
a = a + 1; // add
a = a - 1; // subtract
a = a * 2; // multiply
a = 20 / 10; // divide
a = 5 ** 2; // exponent
a = 10 % 2; // modulus (division remainder)
let b = ++a // increment by 1 before assignment
b = a++ // increment by 1 after assignment
b = --a // decrement by 1 before assignment
b = a-- // decrement by 1 after assignment
Comparrison operators
console.log( true == 1 ); // equal to value - true as boolean values like true/false are also represented as 1 and 0 respectively
console.log( true === 1 ); // equal to value and type - false as values are the same but boolean and number are different types2
console.log( 1 != 2 ); // not equal to value - false
console.log( true !== 1 ); // not equal to value and type - true as not equal to value and type
console.log( 2 > 2 ); // greater than - false as 2 is not greater than 2
console.log( 2 >= 2 ); // greater than or equal to - true as 2 is equal 2
console.log( 1 < 2 ); // less than - true as 1 is less than 2
console.log( 2 <= 2 ); // less than or equal to - true as 2 is equal to 2