# Javascript Operators : The Basics you need to know!

Let's get started ....

While writing the javascript code , we sometimes need to perform the actions like **addition and multiplication** of numbers , **comparing** the values and making some **decisions** . This all can be done using small symbols called as **operators.**

Even though these operators looks simple (= , - , === , % ) , they are known as the building blocks of javascript program . In this blog , we’ll explore the different types of operators and learn how they help our code think, calculate, and make decisions.

![](https://cdn.hashnode.com/uploads/covers/697720f9aaff412f46e7c283/83a448f0-cb69-43a9-b71f-c7f4e38acce6.png align="center")

## **1\] Arithmetic:** `The Engine Room: Powering Your Data`

These are the basics you learned in school, but with a programming twist. They take two values and spit out a new one.  
The types of Artithmetic operators are : **Addition , Multiplication , Division , subtraction and Modulus.**

![](https://cdn.hashnode.com/uploads/covers/697720f9aaff412f46e7c283/80b0c8a6-f6a8-404e-8521-8910e6d77e6e.png align="center")

The modulus operator gives you the remainder . in above eg. you can see 3%9 = 3; means 3 is the remainder . Another example you can take is 20%2 = 0; means 0 is the remainder .  
**Pro Tip:** Use the Modulo operator (`%`) to check if a number is even or odd. If `num % 2` is `0`, it’s even!

## 2\] **Comparison operators**

Comparison operators are used to **compare two values or variables**.  
They check whether a condition is **true or false** and always return a **Boolean value (**`true` **or** `false`**)**.  
The comparison operators are : **greater than , lesser than , not equal to , strict equal to , loose equal to.**

![](https://cdn.hashnode.com/uploads/covers/697720f9aaff412f46e7c283/b9456949-554f-4ab8-8d4e-302f57669af9.png align="center")

## **"The Twin Paradox: Why** `==` **and** `===` **Aren't Friends"**

*   ### The Loose Twin (`==`)
    

The Double Equals is the "chill" friend. It doesn't care about types. If you try to compare a **String** "5" and a **Number** 5, it says, *"I'll just convert one of these so they match. Close enough!"* This hidden conversion is called **Type Coercion**

```javascript
console.log(5 == "5"); // true (JavaScript forces them to match)
console.log(true == 1);  // true (JavaScript treats 1 as true)
```

*   ### The Strict Twin (`===`)
    

The Triple Equals is the "perfectionist" friend. It checks both the **Value** and the **Data Type**. If they aren't identical twins, it returns `false`. No conversions, no excuses.

```javascript
console.log(5 === "5"); // false (One is a Number, one is a String)
console.log(true === 1);  // false (One is a Boolean, one is a Number)
```

## 3\] **Logical:** `The Brain Center: Building Complex Conditions`

These allow your code to **make decisions**. Think of them as the "Logic Gates" of your application.  
The logical operators are : **and , not , or**

**AND operator:**

![AND operator {&&}](https://cdn.hashnode.com/uploads/covers/697720f9aaff412f46e7c283/6a02fde5-32e6-4386-94a3-e64d96a26c60.png align="center")

**OR operator :**

![](https://cdn.hashnode.com/uploads/covers/697720f9aaff412f46e7c283/ddfedac8-9493-4709-b32c-cb7af54c84ac.png align="center")

**NOT operator :**

![](https://cdn.hashnode.com/uploads/covers/697720f9aaff412f46e7c283/ccab9b0f-17d5-4a83-9afa-eb5c56125013.png align="center")

## 4\] **Assignment:** `Code Shortcuts: Levelling Up Your Efficiency`

You already know `=`, but did you know you can do math and assign a value at the same time? well yes you can ! all thanks to assignment operators .It saves space and looks cleaner.

```javascript
var points = 10;

points += 5; // treated as: points = points + 5 (Result: 15)
points -= 3; // treated as: points = points - 3 (Result: 12)
```

## SHORT SUMMARY FOR THE TOPICS YOU READ UNTILL NOW !

<table style="min-width: 125px;"><colgroup><col style="min-width: 25px;"><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><strong>Category</strong></p></td><td colspan="1" rowspan="1"><p><strong>Operator</strong></p></td><td colspan="1" rowspan="1"><p><strong>Name</strong></p></td><td colspan="1" rowspan="1"><p><strong>Rule / Logic</strong></p></td><td colspan="1" rowspan="1"><p><strong>Real-World Example</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></p></td><td colspan="1" rowspan="1"><p>Basic Math</p></td><td colspan="1" rowspan="1"><p>Standard calculation.</p></td><td colspan="1" rowspan="1"><p><code>total = price + tax</code></p></td></tr><tr><td colspan="1" rowspan="1"><p></p></td><td colspan="1" rowspan="1"><p><code>%</code></p></td><td colspan="1" rowspan="1"><p>Modulo</p></td><td colspan="1" rowspan="1"><p>Finds the <strong>remainder</strong>.</p></td><td colspan="1" rowspan="1"><p><code>isEven = (num % 2 === 0)</code></p></td></tr><tr><td colspan="1" rowspan="1"><p><strong>Comparison</strong></p></td><td colspan="1" rowspan="1"><p><code>==</code></p></td><td colspan="1" rowspan="1"><p>Loose</p></td><td colspan="1" rowspan="1"><p>Checks <strong>value</strong> only.</p></td><td colspan="1" rowspan="1"><p><code>5 == "5"</code> (True )</p></td></tr><tr><td colspan="1" rowspan="1"><p></p></td><td colspan="1" rowspan="1"><p><code>===</code></p></td><td colspan="1" rowspan="1"><p>Strict</p></td><td colspan="1" rowspan="1"><p>Checks <strong>value + type</strong>.</p></td><td colspan="1" rowspan="1"><p><code>5 === "5"</code> (False )</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>AND</p></td><td colspan="1" rowspan="1"><p><strong>All</strong> must be true.</p></td><td colspan="1" rowspan="1"><p><code>age &amp;&amp; hassubscription</code></p></td></tr><tr><td colspan="1" rowspan="1"><p></p></td><td colspan="1" rowspan="1"><p><code>||</code></p></td><td colspan="1" rowspan="1"><p>OR</p></td><td colspan="1" rowspan="1"><p><strong>At least one</strong> is true.</p></td><td colspan="1" rowspan="1"><p><code>isWeekend || isHoliday</code></p></td></tr><tr><td colspan="1" rowspan="1"><p></p></td><td colspan="1" rowspan="1"><p><code>!</code></p></td><td colspan="1" rowspan="1"><p>NOT</p></td><td colspan="1" rowspan="1"><p>Flips the truth.</p></td><td colspan="1" rowspan="1"><p><code>!islocked</code> (Unlocked)</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></p></td><td colspan="1" rowspan="1"><p>Shortcut</p></td><td colspan="1" rowspan="1"><p>Math + Save result.</p></td><td colspan="1" rowspan="1"><p><code>score += 10</code> (Add 10)</p></td></tr></tbody></table>

***THANK YOU !***
