# JavaScript Operators Explained (With Simple Examples)

Before writing logic in JavaScript, we need something called **operators**.

Operators are what allow us to **perform actions on values**.

For example, adding numbers, comparing values, or checking conditions.

* * *

### What operators are

An **operator** is a symbol that performs an operation on values.

Simple math example:

```plaintext
2 + 3
```

Here:

*   `2` and `3` are values
    
*   `+` is the operator
    

The operator tells JavaScript **what action to perform**.

* * *

### Arithmetic operators

These are the most basic ones. They work just like school math.

Examples:

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

console.log(a + b); // 15
console.log(a - b); // 5
console.log(a * b); // 50
console.log(a / b); // 2
console.log(a % b); // 0
```

`%` is called the **modulus operator**, and it gives the remainder.

Example:

```plaintext
7 % 2 = 1
```

* * *

### Comparison operators

These operators compare two values and return **true or false**.

Examples:

```plaintext
console.log(5 > 3);  // true
console.log(2 < 1);  // false
```

Two very important ones are:

```plaintext
== 
===
```

Example:

```plaintext
console.log(5 == "5");  // true
console.log(5 === "5"); // false
```

Why?

*   `==` compares **values only**
    
*   `===` compares **value AND type**
    

So `===` is usually safer to use.

* * *

### Logical operators

Logical operators combine conditions.

Three main ones:

**AND (&&)**  
  
Both conditions must be true.

```plaintext
console.log(true && true); // true
```

**OR (||)**  
  
At least one condition must be true.

```plaintext
console.log(true || false); // true
```

**NOT (!)**  
  
Reverses a value.

```plaintext
console.log(!true); // false
```

These are often used inside `if` statements.

* * *

### Assignment operators

Assignment operators store values in variables.

Example:

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

Here `=` assigns the value.

There are also shorthand versions:

```plaintext
x += 5   // same as x = x + 5
x -= 2   // same as x = x - 2
```

These just make code shorter.

* * *

### Small practice idea

Try something like this in the console:

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

console.log(a + b);
console.log(a * b);

console.log(a == b);
console.log(a === b);

console.log(a > 5 && b < 5);
```

This covers arithmetic, comparison, and logical operators in one place.

* * *

### Final thought

Operators are small but very important.  
  
Almost every JavaScript program uses them, from simple math to complex logic.

Once you practice them a little, they become second nature.
