# JavaScript Operators: The Basics You Need to Know

Hey Everyone,

In this blog, we will learn about JavaScript Operators.

In programming, we often need to perform calculations, compare values, or combine conditions.

For example:

*   Add two numbers
    
*   Check if two values are equal
    
*   Verify multiple conditions
    

To perform these actions, JavaScript uses operators.

Let’s understand the most important ones every beginner should know.

* * *

### What Are Operators?

An **operator** is a symbol that tells JavaScript to **perform an operation on values**.

Example:

```javascript
let result = 5 + 3;
console.log(result) // 8
```

Here:

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

### Example

```javascript
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:

```javascript
13
7
30
3.333...
1
```

The `%` operator returns the **remainder of a division**.

Example:

```javascript
10 % 3 = 1
```

* * *

### Comparison Operators

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

| Operator | Meaning |
| --- | --- |
| \== | Equal (value only) |
| \=== | Strict equal (value + type) |
| != | Not equal |
| \> | Greater than |
| < | Less than |

* * *

## Example

```javascript
let x = 10;
let y = 20;

console.log(x > y);
```

Output

```javascript
false
```

* * *

### Difference Between and =

This is **very important in JavaScript**.

Using ==

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

Why?  
  
Because `==` **converts types before comparing**.

* * *

Using ===

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

Because:

*   `5` → number
    
*   `"5"` → string
    

`===` checks **both value and type**.

Best practice:  
  
**<mark class="bg-yellow-200 dark:bg-yellow-500/30">Use </mark>** `===` **<mark class="bg-yellow-200 dark:bg-yellow-500/30"> in most cases.</mark>**

### Logical Operators

Logical operators combine **multiple conditions**.

### Example: AND (&&)

```javascript
let age = 20;
let hasID = true;

if (age >= 18 && hasID) {
  console.log("Entry allowed");
}
```

Both conditions must be **true**.

* * *

### Example: OR (||)

```javascript
let isWeekend = true;
let isHoliday = false;

if (isWeekend || isHoliday) {
  console.log("You can relax");
}
```

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

* * *

### Example: NOT (!)

```javascript
let isLoggedIn = false;

console.log(!isLoggedIn); // true
```

### Assignment Operators

Assignment operators are used to **assign or update values**.

| Operator | Meaning |
| --- | --- |
| \= | Assign value |
| += | Add and assign |
| \-= | Subtract and assign |

* * *

### Example

```javascript
let score = 10;

score += 5;

console.log(score); // 15
```

Equivalent to:

```plaintext
score = score + 5;
```

* * *

### Practice Assignment

Try these examples in your browser console.

* * *

### 1\. Arithmetic Operations

```javascript
let a = 8;
let b = 4;

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

* * *

### 2\. Compare Values

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

Observe the difference.

* * *

### 3\. Logical Condition

```javascript
let age = 19;
let hasTicket = true;

if (age >= 18 && hasTicket) {
  console.log("You can enter the event");
}
```

* * *

And now, you know what JS operators are.

If you have any doubt or want to connect, feel free to drop a comment — I’d be happy to help.

Thanks for reading, and see you in the next blog!

Peace ✌️ and Happy Learning!
