JavaScript Basics: Operators and Expressions
Source: Dev.to

What are Operators and Expressions?
Operators – symbols that tell JavaScript to perform specific actions (addition, comparison, logical checks, etc.).
Expressions – combinations of values, variables, and operators that evaluate to a single value.
let result = 5 + 3; // Expression: 5 + 3
console.log(result); // Output: 8
Here, the + is an operator, and 5 + 3 is an expression.
Arithmetic Operators
Arithmetic operators are used for mathematical calculations.
| Operator | Description | Example | Result |
|---|---|---|---|
+ | Addition | 5 + 3 | 8 |
- | Subtraction | 5 - 2 | 3 |
* | Multiplication | 4 * 2 | 8 |
/ | Division | 10 / 2 | 5 |
% | Modulus (remainder) | 10 % 3 | 1 |
++ | Increment (by 1) | let x = 5; x++ | 6 |
-- | Decrement (by 1) | let y = 5; y-- | 4 |
** | Exponentiation | 2 ** 3 | 8 |
Example
let a = 10;
let b = 3;
console.log(a + b); // 13
console.log(a % b); // 1
console.log(a ** b); // 1000
Comparison Operators
Comparison operators compare two values and return a Boolean (true or false).
| Operator | Description | Example | Result |
|---|---|---|---|
== | Equal to (value only) | 5 == "5" | true |
=== | Strict equal (value & type) | 5 === "5" | false |
!= | Not equal (value only) | 5 != "6" | true |
!== | Strict not equal (value & type) | 5 !== "5" | true |
> | Greater than | 7 > 5 | true |
>= | Greater than or equal to | 5 >= 5 | true |
Logical Operators
Logical operators combine or invert Boolean conditions, often inside if statements.
| Operator | Name | Description |
|---|---|---|
&& | AND | Both conditions must be true |
| ` | ` | |
! | NOT | Inverts a condition |
Examples
// Using OR
(5 = 18 && hasID) {
console.log("You are allowed to enter.");
} else {
console.log("Access denied.");
}
&& ensures both conditions (age >= 18 and hasID) must be true. If either is false, the condition fails.
Final Thoughts
Understanding operators and expressions is crucial because they form the decision‑making and calculation backbone of JavaScript programs.
- Use arithmetic operators for math‑related tasks.
- Use comparison operators to compare values.
- Use logical operators to combine conditions and control program flow.
Stay tuned for more insights as you continue your journey into web development!
Check out the YouTube Playlist for great JavaScript content, from basic to advanced topics.
Subscribe to the CodenCloud YouTube channel for more programming concepts and tutorials.