Module 3: Operators and User Interaction
Assignment and Arithmetic Operators
Assignment Operator (=
):
Assigns a value to a variable.
let x = 10; let y = x; // y is now 10
Arithmetic Operators: Perform mathematical calculations.
+
(Addition):5 + 3
is8
-
(Subtraction):5 - 3
is2
*
(Multiplication):5 * 3
is15
/
(Division):10 / 4
is2.5
%
(Modulus/Remainder):10 % 3
is1
(10 divided by 3 is 3 with a remainder of 1)**
(Exponentiation - ES2016):2 ** 3
is8
(2 to the power of 3)++
(Increment): Increases a number by 1.x++
(postfix) or++x
(prefix).--
(Decrement): Decreases a number by 1.x--
(postfix) or--x
(prefix).
let a = 5; let b = 2; console.log(a + b); // 7 console.log(a * b); // 10 console.log(a / b); // 2.5 console.log(a % b); // 1 console.log(a ** b); // 25 (5*5) a++; // a is now 6 b--; // b is now 1