# JavaScript Operators: The Basics You Need to Know


When I started learning **JavaScript**, I quickly realized that almost everything in programming involves **operators**.

At first, they looked like simple math symbols like `+` or `-`. But soon I learned that operators can do much more — they help us **perform calculations, compare values, and make decisions in our code**.

In this beginner-friendly guide, we’ll explore the **most important JavaScript operators** with simple examples you can try in your console.

* * *

# What Are Operators?

In simple words:

**Operators are symbols that perform operations on values or variables.**

Example:

```plaintext
let result = 5 + 3;
```

Here:

*   `5` and `3` are **operands**
    
*   `+` is the **operator**
    

![](https://cdn.hashnode.com/uploads/covers/696e0f60efc349ce08c08cc3/4a7ebec5-a004-46a4-a21c-409ceb96f8c6.png align="center")

# 1\. Arithmetic Operators

Arithmetic operators are used for **basic mathematical calculations**.

| Operator | Meaning | Example |
| --- | --- | --- |
| + | Addition | 5 + 3 |
| \- | Subtraction | 5 - 3 |
| \* | Multiplication | 5 \* 3 |
| / | Division | 6 / 2 |
| % | Modulus (remainder) | 5 % 2 |

### Example in Console

```plaintext
let a = 10;
let b = 3;

console.log(a + b); 
console.log(a - b);
console.log(a * b);
console.log(a / b);
console.log(a % b);
```

### Output

```plaintext
13
7
30
3.33
1
```

![](https://cdn.hashnode.com/uploads/covers/696e0f60efc349ce08c08cc3/a480dc9f-3350-4fee-8130-a2c6979ed3ba.png align="center")

# 2\. Comparison Operators

Comparison operators are used when we want to **compare two values**.  
They always return **true or false**.

| Operator | Meaning |
| --- | --- |
| \== | Equal to |
| \=== | Strict equal |
| != | Not equal |
| \> | Greater than |
| < | Less than |

### Example

```plaintext
console.log(5 > 3);
console.log(10 < 7);
console.log(5 == "5");
console.log(5 === "5");
```

### Output

```plaintext
true
false
true
false
```

* * *

# The Important Difference: `==` vs `===`

This is something every beginner should understand clearly.

```plaintext
console.log(5 == "5");
```

Result:

```plaintext
true
```

Why? Because `==` only checks **value**, not type.

Now look at this:

```plaintext
console.log(5 === "5");
```

Result:

```plaintext
false
```

Because `===` checks **value AND data type**.

![](https://cdn.hashnode.com/uploads/covers/696e0f60efc349ce08c08cc3/a6944b38-63d6-44fb-91f8-36de1e3ab28c.png align="center")

# 3\. Logical Operators

Logical operators are used when we want to **combine conditions**.

| Operator | Meaning |
| --- | --- |
| && | AND |
|  |  |
| ! | NOT |

### Example

```plaintext
let age = 20;

console.log(age > 18 && age < 30);
console.log(age > 25 || age < 18);
console.log(!(age > 18));
```

### Output

```plaintext
true
false
false
```

# 4\. Assignment Operators

Assignment operators are used to **assign values to variables**.

The most common one is `=`.

```plaintext
let x = 10;
```

But JavaScript also provides **shortcut assignment operators**.

| Operator | Example | Meaning |
| --- | --- | --- |
| \= | x = 5 | assign value |
| += | x += 5 | x = x + 5 |
| \-= | x -= 2 | x = x - 2 |

### Example

```plaintext
let x = 10;

x += 5;
console.log(x);

x -= 3;
console.log(x);
```

### Output

```plaintext
15
12
```

Operators may seem small, but they are **one of the most important parts of JavaScript**. Almost every program uses them for **calculations, comparisons, and decision making**.
