Create two variables, a with a value of 15 and b with a value of 4, then log the remainder when a is divided by b to the console.
Operators perform actions on values and variables. For example, the +
operator adds two numbers, and the ===
operator compares two values for equality and type.
Used for mathematical operations:
+
(Addition) → 5 + 3 // 8
-
(Subtraction) → 10 - 4 // 6
*
(Multiplication) → 6 * 7 // 42
/
(Division) → 8 / 2 // 4
%
(Modulus) → 7 % 3 // 1
**
(Exponentiation) → 2 ** 3 // 8
Assign values to variables:
=
(Simple assignment) → let x = 5;
+=
(Add and assign) → x += 3; // same as x = x + 3
-=
(Subtract and assign) → x -= 2;
Compare values and return true
or false
:
==
Equal (loose comparison, type conversion allowed)===
Strict equal (no type conversion)!=
Not equal!==
Strict not equal>
Greater than<
Less than>=
Greater than or equal<=
Less than or equalUsed for logical comparisons:
&&
(AND) → true && false // false
||
(OR) → true || false // true
!
(NOT) → !true // false
+
Concatenates strings."Hello" + " World"
→ "Hello World"
An expression is any valid set of literals, variables, operators, and functions that returns a value.
Example:let result = (5 + 3) * 2; // 16