JavaScript

Operators & Expressions

Master JavaScript operators! Learn arithmetic, comparison, logical operators, and how to build complex expressions.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Master JavaScript operators! Learn arithmetic, comparison, logical operators, and how to build complex expressions. This hands-on tutorial focuses on practical implementation of operators & expressions concepts.

Operators & Expressions

Operators are symbols that perform operations on values. They're the building blocks for creating logic and calculations in your code!

1. What are Operators? ⚙️

What is it? Operators are special symbols (like +, -, =, !) that perform operations on one or more operands (values/variables).

Why use it? They allow you to manipulate data—add numbers, compare values, combine logic, and assign results.

How it works: Operand1 Operator Operand2 (e.g., 5 + 3).

2. Arithmetic Operators ➕➖

Used for performing mathematical calculations.

  • + (Addition)
  • - (Subtraction)
  • * (Multiplication)
  • / (Division)
  • % (Modulus/Remainder)
  • ** (Exponentiation)
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

3. Comparison Operators 🔍

Used to compare two values. They always return a Boolean (true or false).

Strict vs Loose Equality ⚠️

  • == (Loose Equality): Converts types before comparing. Avoid this.
  • === (Strict Equality): Checks value AND type. Use this.
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

4. Logical Operators 🧠

Used to combine multiple conditions.

  • && (AND): True if both are true.
  • || (OR): True if at least one is true.
  • ! (NOT): Inverts the value.

Short-Circuit Evaluation ⚡

JavaScript stops evaluating as soon as the result is known.

  • false && ... -> Stops (Result is false)
  • true || ... -> Stops (Result is true)
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

5. Assignment Operators 📝

Used to assign values to variables.

  • = (Assign)
  • += (Add and assign)
  • -= (Subtract and assign)
  • ++ (Increment)
  • -- (Decrement)
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

6. Ternary Operator ❓

A shorthand for if-else statements.

Syntax: condition ? trueValue : falseValue

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

7. Operator Precedence 📊

The order in which operators are evaluated.

  1. () (Parentheses) - Highest
  2. ** (Exponentiation)
  3. *, /, % (Multiplication/Division)
  4. +, - (Addition/Subtraction)
  5. =, += (Assignment) - Lowest
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

8. Nullish Coalescing (??) 🎯

(Covered in ES6+ Features, but relevant here) Returns the right side ONLY if the left side is null or undefined.

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

Practical Example: Shopping Cart Logic 🛒

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

AI Mentor

Confused about "JavaScript operators, precedence, short-circuit evaluation, and ternary operator"? Ask our AI mentor for a simplified explanation.

Quiz

Quiz

Question 1 of 4

What is the result of 10 % 3?

3
1
0
3.33

Key Takeaways

Arithmetic: +, -, *, /, % (Remainder), ** (Power).
Comparison: Always use === (Strict) over == (Loose).
Logical: && (AND), || (OR), ! (NOT).
Short-Circuit: || can provide default values.
Ternary: condition ? true : false is a one-line if-else.

What's Next?

Now that you can manipulate values, let's learn about Strings & Template Literals to handle text like a pro!

Keep coding! 🚀