DEV Community

Cover image for JavaScript Operators: The Fundamentals You Need to Know
Ritam Saha
Ritam Saha

Posted on

JavaScript Operators: The Fundamentals You Need to Know

Introduction: The Silent Decision-Makers in Your Code

Imagine you're building a calculator.

You enter two numbers.
You press a button.
You expect a result.

Behind that simple action lies something powerful — operators.

Operators are the symbols that allow JavaScript to perform calculations, compare values, make decisions, and update data. They are small, but they drive almost every meaningful line of logic in your program.

If variables store data, operators are what make that data useful for operations.

In this blog, we’ll break down JavaScript operators in the most practical way possible — focusing on everyday usage, real console examples, and clear distinctions that every beginner must understand.


What Are Operators?

In simple terms, Operators are symbols that perform operations on values and variables. You can think of them as action triggers.

Example:

let result = 5 + 3;
Enter fullscreen mode Exit fullscreen mode

Here:

  • 5 and 3 are operands means on which the operation will happen.
  • + is the operator based on which the operation will happen.
  • The output is 8.

Without operators, JavaScript would only store values — it wouldn’t do anything with them.

There are different categories of operators that are used in daily basis. Let's discuss them one by one.

Category Operators Purpose
Arithmetic + - * / % Perform mathematical calculations
Comparison == === != > < Compare two values
Logical &&
Assignment = += -= Assign or update values

Arithmetic Operators

These are the most familiar ones. They basically perform different mathematical calculations. There can be further classified into two sections.

  • Unary Operators: Deals with only one operand
  • Binary Operator: Deals with two operands

The following are examples of Unary Operators:

let num = 10;
console.log(num++); //10 (Post-increment: returns the value before incrementing)
console.log(++num); //12 (Pre-increment: increments the value first, then returns it)
console.log(num--); //12 (Post-decrement: returns the value before decrementing)
console.log(--num); //10 (Pre-decrement: decrements the value first, then returns it)
Enter fullscreen mode Exit fullscreen mode

Now, let's go through some examples of Binary Operators.

let a = 10;
let b = 3;

console.log(a + b); // 13
console.log(a - b); // 7
console.log(a * b); // 30
console.log(a / b); // 3.3333...
console.log(a % b); // 1 (remainder of the division)
console.log(a ** b); //1000 (a raised to the power of b)
Enter fullscreen mode Exit fullscreen mode

Relational Operators

These operators compare two values and return a Boolean value i.e, true or false. Let's understand these through an example:

let a = 10;
let b = 3;

console.log(a > b); // true
console.log(a < b); // false
console.log(a >= b); // true
console.log(a <= b); // false
console.log(a == b); // false
console.log(a != b); // true
Enter fullscreen mode Exit fullscreen mode

There's also a concept of strict equality check in comparison which is done by ===. Now a question that should arise is, what is the difference between == and ===??

This is one of the most misunderstood topics for beginners.

== (Loose Equality)

  • Compares values
  • Converts types automatically if needed
console.log(5 == "5"); // true (Because JavaScript converts "5" (string) into number 5)
Enter fullscreen mode Exit fullscreen mode

=== (Strict Equality)

  • Compares value & data type for primitive values and for non-primitive values, it checks whether the values are sharing same memory reference or not.
  • No type conversion
console.log(5 === "5"); // false (Number is not equal to string)
Enter fullscreen mode Exit fullscreen mode

In real-world development:
Always prefer === over ==.
It prevents unexpected bugs and keeps your logic predictable.

Logical Operators

Logical operators are the backbone of decision-making in JavaScript. They are used to combine or invert conditions mostly used in control-flow. There are mainly 3 logical operators. Let's understand them one by one through examples:

AND (&&)

Returns true only if both conditions are true, otherwise false.

console.log(true && false); // false
Enter fullscreen mode Exit fullscreen mode

OR (||)

Returns true if at least one condition is true.

console.log(true || false); // true
Enter fullscreen mode Exit fullscreen mode

NOT (!)

To reverses the boolean value.

console.log(!true); // false
Enter fullscreen mode Exit fullscreen mode

Logical Operators Truth Table

A B AND OR !A
true true true true false
true false false true false
false true false true true
false false false false true

I will recommend you to explore all these cases by youself to have more understanding about their use cases!

Assignment Operators

Assignment operators are used to assign or update values. These operators provide cleaner, more readable, more efficient code.

let score = 10;

score += 5; // score = score + 5
console.log(score); // 15

score -= 3; // score = score - 3
console.log(score); // 12
Enter fullscreen mode Exit fullscreen mode

Conclusion

JavaScript operators may look small, but they control how your program behaves.

They:

  • Perform calculations
  • Compare values
  • Drive decision-making
  • Update data efficiently

Mastering operators means mastering the core mechanics of JavaScript logic.

Before moving into advanced concepts like functions, arrays, or asynchronous programming, you must be fully comfortable with operators. They are not optional knowledge — they are foundational.

If your logic is weak, your application will be unpredictable.
If your understanding of operators is strong, your code becomes intentional.

And that’s the difference between writing code… and engineering solutions.


Top comments (0)