JavaScript Basics: Operators and Expressions

Published: (February 26, 2026 at 02:30 AM EST)
3 min read
Source: Dev.to

Source: Dev.to

Cover image for JavaScript Basics: Operators and Expressions

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.

OperatorDescriptionExampleResult
+Addition5 + 38
-Subtraction5 - 23
*Multiplication4 * 28
/Division10 / 25
%Modulus (remainder)10 % 31
++Increment (by 1)let x = 5; x++6
--Decrement (by 1)let y = 5; y--4
**Exponentiation2 ** 38

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).

OperatorDescriptionExampleResult
==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 than7 > 5true
>=Greater than or equal to5 >= 5true

Logical Operators

Logical operators combine or invert Boolean conditions, often inside if statements.

OperatorNameDescription
&&ANDBoth conditions must be true
``
!NOTInverts 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.

0 views
Back to Blog

Related posts

Read more »