Learn more about one of the world’s most popular programming languages.
- Arithmetic Operators
- Increment/Decrement Operators
- Assignment Operators
- Comparison Operators
- Other Operators
|+ (Addition)||3 + 5|
|– (Subtraction)||10 – 4|
|* (Multiplication)||7 * 5|
|/ (Division)||8 / 2|
|** (exponent or power)||2 ** 4|
|% (modulo or remainder)||8 % 4|
Increment (two plus sign)
++ & Decrement (two minus sign)
-- Operators are used to increase or decrease the value of a variable by 1. Depending on whether the operator sign is used before or after the variable, it produces a different result. However, it still increments or decrements by 1.
let count = 0; console.log(count); // prints 0 count++; // first assign the current value back to count and then increase it by 1 ++count; // first increase the value by 1 and then assign the new value to count
|++ (increment the value by 1)||let count = 0;count++;++count;|
|— (decrement the value by 1)||let count = 0;count–;–count;|
Assignment operator or equal sign
Increment and Decrement Operators also have a shorthand notation that uses the assignment operator. While increment operator
++ and decrement operator
-- is used to increase or decrease the value by 1, sometimes there is a need to increase or decrease the value by a different amount. In this case a variation of increment
+= and decrement
-= is used.
|= (Assignment)||let count = 0;|
|+= (Addition Assignment)||let count = 0;count += 5; // equivalent to count = count + 5;console.log(count) // displays 5|
|-= (Subtraction Assignment)||let count = 5;count -= 5; // equivalent to count = count – 5;console.log(count) // displays 0|
|*= (Multiplication Assignment)||let count = 1;count *= 5; // equivalent to count = count * 5;console.log(count) // displays 5|
|/= (Division Assignment)||let count = 10;count /= 5; // equivalent to count = count / 5;console.log(count) // displays 2|
== and strict
=== or strict equality comparison.
== sign compares only the values to be either truthy or falsy while
=== compares both the values and as well the type of both the values to be equal for a more strict comparison.
|== (non strict equality)||0 == 0 // true0 == false // true as both values are falsy|
|=== (strict equality)||0 === 0 // true0 === false // false as types are different|
|!= (non strict not equal)||1 != 0 // true1 != true // false as both values are truthy|
|!== (strict not equal)||1 != 0 // true1 !== true // true as both types are different|
|> (greater than)||5 > 4 // true|
|>= (greater than or equal to)||5 >= 5 // true|
|< (less than)||7 < 10 //true|
|<= (less than or equal to)||7 <= 7 //true|
const whatToWear = isWeekend ? “jeans”: “suit”;
Get hands-on experience writing code with interactive tutorials in our free online learning platform.
- Free and fun
- Designed for beginners
- No downloads or setup required