# JavaScript Operators: The Basics You Need to Know

Hi! In this blog you will get to know about operators like +, - ,\* etc.. and their precedence order.

## What operators are

In JavaScript, operators are special symbols or keywords that perform operation on values (operands) and produce result.

For example:

```javascript
let productPrice = 50;
let deliveryCharge = 5;
    console.log(productPrice + deliveryCharge); // 55
```

Here:

- `productPrice` and `deliveryCharge` are operands (values on which operartion is performed).
- `+` is an operator (performs addition).

**Types of operators in JavaScript**

There are different categories for operators in JavaScript

1. **Arithmetic Operators**

Used to perform arithmetic calculations.

| Operator | Meaning | Example | Result |
| --- | --- | --- | --- |
| + | Addition | 5 + 5 | 10 |
| \- | Subtraction | 10 - 5 | 5 |
| / | Divide | 15 / 5 | 3 |
| \* | Multiplication | 5 \* 4 | 20 |
| % | Remainder | 18 % 4 | 2 |
| \*\* | Exponential | 2 \*\* 4 | 16 |
| ++ | Increment | a++ | Adds 1 |
| \-- | Decrement | a-- | subtracts 1 |

1. **Assignment Operators**

Used to update or assign values in variables.

| **Operator** | **Example** | **Equivalent to** |
| --- | --- | --- |
| \= | a = 10 | Assign 10 in a |
| += | a+=5 | a = a + 5 |
| \-= | a-=5 | a = a - 5 |
| /= | a/=3 | a = a / 3 |
| %= | a%=4 | a = a % 4 |
| \*= | a\*=12 | a = a \* 12 |
| \*\*= | a\*\*=7 | a = a \*\* 7 |

1. **Comparison Operators**

Used to compare two values. They return a Boolean (true or false).

| Operator | Meaning | Example |
| --- | --- | --- |
| \== | Loose equality | 5 == "5" → true |
| \=== | Strict equality | 5 === "5" → false |
| != | Loose inequality | 5 != "6" → true |
| !== | Strict inequally | 5 !== "5" → true |
| \> | Greater than | 10 > 5 → true |
| &lt; | Less than | 5 &lt; 10 → true |
| \>= | Greater than or equal | 10 >= 10 → true |
| &lt;= | Less than or equal | 5 &lt;= 10 → true |

**Important :** Prefer `===` over `==` and `!==` over`!=` because strict comparisons don't perform automatic type conversion.

4. **Logical Operators**

Used to combine or reverse Boolean conditions.

| Operator | Meaning | Example |
| --- | --- | --- |
| && | AND | true && false → false |
| \|\| | OR | true \|\| false → true |
| ! | NOT | !true → false |

## Comparison Table

| P | Q | P && Q | P \|\| Q | !P |
| --- | --- | --- | --- | --- |
| true | true | true | true | false |
| true | false | false | true | false |
| false | true | false | true | true |
| false | false | false | false | true |

---

## Operators Precedence Order

![](https://cdn.hashnode.com/uploads/covers/6777f42b53876daac30d009e/d1a5e4a2-2934-4af8-825d-e4935c2be614.png align="center")

---

Thanks for reading this blog💌. Hope it provided you useful stuff about JavaScript.
