# JavaScript Operators: The Basics You Need to Know

### Learning JavaScript One Night at a Time

It was around **11:30 PM in my hostel room**. The corridor lights were still on, someone down the hall was arguing about which movie to watch, and a couple of friends were debating whether to go to outside or order food online (they aren't eating hostel's mess food :P) ).

Meanwhile, I was sitting with my laptop open, trying to understand something simple but important in JavaScript — **operators**.

At first they looked harmless. Just small symbols like `+`, `-`, `==`, `&&`, `=`. But the more I explored them, the more I realized something interesting.

**JavaScript operators are everywhere — even in hostel life.**

Every time we split a food bill, compare room numbers, or decide whether to go to the mess or order food, we are essentially doing what operators do in programming: **calculating, comparing, and making decisions**.

So let’s explore the **basic JavaScript operators**, but through situations that every hostel student will instantly recognize.

* * *

## What Are Operators?

In JavaScript, **operators are symbols that perform operations on values or variables**.

Think of them as **instructions telling the program what to do**.

For example:

```javascript
let total = 5 + 3;
```

Here:

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

JavaScript performs the operation and produces `8`.

Operators are essential because they allow programs to:

*   perform calculations
    
*   compare values
    
*   make decisions
    
*   update variables
    

Without operators, programming would be almost impossible.

* * *

### Categories of JavaScript Operators

Before diving deeper, here is a quick overview.

| Operator Type | Purpose | Examples |
| --- | --- | --- |
| Arithmetic Operators | Perform calculations | +, -, \*, /, % |
| Comparison Operators | Compare values | \==, ===, !=, >, < |
| Logical Operators | Combine conditions | &&, |
| Assignment Operators | Assign/update variables | \=, +=, -= |

Now let’s explore each category using **real hostel scenarios**.

* * *

## 1\. Arithmetic Operators

Arithmetic operators perform **basic mathematical operations**.

If you live in a hostel, you already use these operations daily, especially when **splitting food bills**.

| Operator | Meaning |
| --- | --- |
| `+` | Addition |
| `-` | Subtraction |
| `*` | Multiplication |
| `/` | Division |
| `%` | Remainder |

* * *

### Example: Splitting a Late-Night Food Order

### Imagine four hostel friends order food worth **₹400**.

```javascript
let totalBill = 400;
let friends = 4;

console.log(totalBill / friends);
```

Output:

```plaintext
100
```

Each friend pays **₹100**.

Here `/` is the **division operator**.

* * *

### Example: Total Maggi Packets Needed

Suppose each friend wants **2 packets of Maggi**, and there are **5 friends**.

```javascript
let friends = 5;
let maggiPerPerson = 2;

console.log(friends * maggiPerPerson);
```

Output:

```plaintext
10
```

So you need **10 packets of Maggi**.

* * *

### Example: The `%` (Modulus) Operator

This operator returns the **remainder**.

Example:

```javascript
console.log(10 % 3);
```

Output:

```plaintext
1
```

In simple terms:

```plaintext
10 ÷ 3 = 3 remainder 1
```

This operator is often used for things like **checking even or odd numbers**.

* * *

## 2\. Comparison Operators

Comparison operators are used to **compare two values**.

They always return a **Boolean result**:

```plaintext
true
false
```

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

* * *

### Example: Mess Closing Time

Suppose the mess closes at **10 PM**.

```javascript
let currentTime = 11;

console.log(currentTime > 10);
```

Output:

```plaintext
true
```

Meaning: the mess is already closed.

Time to order food online instead.

* * *

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

This is one of the most important concepts for beginners.

### Loose Equality (`==`)

`==` compares **values only**, and JavaScript may convert data types automatically.

Example:

```javascript
console.log(8 == "8");
```

Output:

```plaintext
true
```

JavaScript converts `"8"` (string) into the number `8`.

* * *

### Strict Equality (`===`)

`===` compares **both value AND type**.

```javascript
console.log(8 === "8");
```

Output:

```plaintext
false
```

Because:

```plaintext
8   → number
"8" → string
```

Even though the values look similar, the **types are different**.

For this reason, most developers prefer using `===`.

* * *

## 3\. Logical Operators

Logical operators allow us to **combine multiple conditions**.

They are commonly used in decision-making situations.

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

* * *

### Example: Deciding Whether to Go to the Mess

Typical hostel logic:

> Go to the mess **only if the food is good AND you are hungry**.

```javascript
let foodIsGood = true;
let hungry = true;

console.log(foodIsGood && hungry);
```

Output:

```plaintext
true
```

Both conditions must be true.

* * *

### Example: Ordering Food Online

Hostel logic again:

> Order food if **mess food is bad OR you are lazy to walk**.

```javascript
let messFoodBad = true;
let lazy = false;

console.log(messFoodBad || lazy);
```

Output:

```plaintext
true
```

Only **one condition** needs to be true.

* * *

### Example: NOT Operator

Imagine you planned to study, but you're **not sleepy**.

```javascript
let sleepy = false;

console.log(!sleepy);
```

Output:

```plaintext
true
```

The NOT operator simply **reverses the value**.

* * *

### Truth Table for Logical Operators

<table style="min-width: 100px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><td colspan="1" rowspan="1"><p>A</p></td><td colspan="1" rowspan="1"><p>B</p></td><td colspan="1" rowspan="1"><p>A &amp;&amp; B</p></td><td colspan="1" rowspan="1"><p>A || B</p></td></tr><tr><td colspan="1" rowspan="1"><p>true</p></td><td colspan="1" rowspan="1"><p>true</p></td><td colspan="1" rowspan="1"><p>true</p></td><td colspan="1" rowspan="1"><p>true</p></td></tr><tr><td colspan="1" rowspan="1"><p>true</p></td><td colspan="1" rowspan="1"><p>false</p></td><td colspan="1" rowspan="1"><p>false</p></td><td colspan="1" rowspan="1"><p>true</p></td></tr><tr><td colspan="1" rowspan="1"><p>false</p></td><td colspan="1" rowspan="1"><p>true</p></td><td colspan="1" rowspan="1"><p>false</p></td><td colspan="1" rowspan="1"><p>true</p></td></tr><tr><td colspan="1" rowspan="1"><p>false</p></td><td colspan="1" rowspan="1"><p>false</p></td><td colspan="1" rowspan="1"><p>false</p></td><td colspan="1" rowspan="1"><p>false</p></td></tr></tbody></table>

This table shows how logical operators behave when combining conditions.

* * *

## 4\. Assignment Operators

Assignment operators are used to **store values in variables**.

The most common one is `=`.

Example:

```javascript
let balance = 500;
```

Here the variable `balance` is assigned the value **500**.

* * *

### Example: Tracking Hostel Expenses

Imagine you start the week with **₹500 in your wallet**.

```javascript
let balance = 500;
```

Then you spend **₹120 on snacks**.

```javascript
balance -= 120;
```

Now your balance becomes:

```plaintext
380
```

The `-=` operator is simply shorthand for:

```javascript
balance = balance - 120;
```

* * *

### Another Example

```javascript
let points = 10;

points += 5;
console.log(points);
```

Output:

```plaintext
15
```

Instead of writing:

```plaintext
points = points + 5
```

We write:

```plaintext
points += 5
```

Cleaner and easier to read.

* * *

### Small Practice Example

Let’s combine everything together.

```javascript
let num1 = 12;
let num2 = 4;

console.log(num1 + num2);
console.log(num1 * num2);

console.log(num1 == num2);
console.log(num1 === num2);

let hungry = true;
let messOpen = false;

if (hungry && messOpen) {
    console.log("Go to the mess");
} else {
    console.log("Order food online");
}
```

* * *

## Final Thoughts from a Hostel Room

That night in the hostel room, after experimenting with these operators in the console, one thing became clear to me.

Programming often starts with **very small building blocks**.

Operators are just symbols — `+`, `==`, `&&`, `=` — but they are what allow programs to **calculate, compare, and make decisions**.

And strangely enough, once you start noticing them, you realize that **hostel life itself is full of operator logic**:

*   splitting food bills
    
*   deciding whether to go to the mess
    
*   tracking weekly expenses
    
*   comparing time before deadlines
    

All of it mirrors the same ideas used in programming.

So the next time you see a simple operator in JavaScript, remember: it may be a tiny symbol, but it controls how your program **thinks and behaves**.

And somewhere in a hostel room, another developer is probably learning the same lesson — one late-night coding session at a time.

* * *

**Hostel Programmer Life continues…**
