# JavaScript Operators: The Simple Guide to Making Your Code "Do Things"

# What are Operators?

In simple terms, an operator is a special symbol used to perform operations on values and variables.

For example, in `5 + 2`, the `+` is the operator. It tells JavaScript: "Take these two numbers and add them together."

## 1\. Arithmetic Operators (The Math Stuff)

These are the ones you already know from school. They allow you to perform basic calculations.

*   `+` (Addition): Adds values.
    
*   `-` (Subtraction): Subtracts values.
    
*   `*` (Multiplication): Multiplies values.
    
*   `/` (Division): Divides one value by another.
    
*   `%` (Remainder/Modulo): Gives you what is left over after division.
    

**Console Example:**

```javascript
let apples = 10;
let friends = 3;

console.log(apples + 5); // 15
console.log(apples * 2); // 20
console.log(apples % friends); // 1 (Because 3 goes into 10 three times, with 1 left over)
```

## 2\. Assignment Operators

These are used to **set** or **update** the value of a variable.

*   `=` : The basic assignment (Sets `x` to `5`).
    
*   `+=` : Adds a value to the current variable and updates it.
    
*   `-=` : Subtracts a value from the current variable and updates it.
    

**Console Example:**

```javascript
let score = 10;
score += 5; // Same as: score = score + 5
console.log(score); // 15
```

## 3\. Comparison Operators

We use these to compare two values. The result is always **True** or **False**.

*   `>` and `<` : Greater than and less than.
    
*   `==` : Equal to (checks the value only).
    
*   `===` : **Strict** equal to (checks the value AND the data type).
    

### The Big Difference: `==` vs `===`

This is a common trap for beginners.

*   `5 == "5"` is **true** because JavaScript tries to be "helpful" and ignores that one is a number and one is text.
    
*   `5 === "5"` is **false** because they are different types. **Always use** `===` **to avoid bugs!**
    

## **4\. Logical Operators**

These help us combine multiple conditions together.

*   `&&` (AND): True only if **both** sides are true.
    
*   `||` (OR): True if **at least one** side is true.
    
*   `!` (NOT): Flips the value (True becomes False).
    

![truth table for logical operators, AI generated](https://encrypted-tbn2.gstatic.com/licensed-image?q=tbn:ANd9GcT3zwcXdCYbwsjdcbxyfobdxfRr9rzdxxflbbgcGgjw6UEBRyHFiIsTWhkvbi-mOLP1ydIUTCJXGJjyVNNhpfJiOZTQhJDVrfrZmVmvpGwAA_9M5Qs align="center")

**Console Example:**

```javascript
let isSunny = true;
let hasFreeTime = true;

if (isSunny && hasFreeTime) {
    console.log("Go for a walk!"); 
}
```

* * *

## Quick Summary Table

<table style="min-width: 75px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1"><p><strong>Category</strong></p></td><td colspan="1" rowspan="1"><p><strong>Symbols</strong></p></td><td colspan="1" rowspan="1"><p><strong>Use Case</strong></p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>Arithmetic</strong></p></td><td colspan="1" rowspan="1"><p><code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>, <code>%</code></p></td><td colspan="1" rowspan="1"><p>Doing math</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>Comparison</strong></p></td><td colspan="1" rowspan="1"><p><code>==</code>, <code>===</code>, <code>&gt;</code>, <code>&lt;</code></p></td><td colspan="1" rowspan="1"><p>Comparing values</p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>Logical</strong></p></td><td colspan="1" rowspan="1"><p><code>&amp;&amp;</code>, `</p></td><td colspan="1" rowspan="1"><p></p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>Assignment</strong></p></td><td colspan="1" rowspan="1"><p><code>=</code>, <code>+=</code>, <code>-=</code></p></td><td colspan="1" rowspan="1"><p>Storing or changing values</p></td></tr></tbody></table>
