# JavaScript Operators: The Basics You Need to Know

When writing JavaScript programs, we often need to perform operations on values. For example, we might need to add numbers, compare two values, or check multiple conditions before making a decision.

To perform these tasks, JavaScript provides **operators**. An **operator** is a symbol that performs an operation on one or more values (called operands).

For example:

```plaintext
let sum = 5 + 3;
```

Here:

```plaintext
+   → operator
5,3 → operands
```

The operator performs an action on the values.

### Arithmetic Operators

Arithmetic operators are used to perform mathematical calculations. These are the most basic operators you will encounter in programming.

Example:

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

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

Output:

```plaintext
15
5
50
2
0
```

The modulus operator `%` returns the remainder after division.

Example:

```plaintext
console.log(7 % 3);
```

Output:

```plaintext
1
```

### Comparison Operators

Comparison operators are used to compare two values. They usually return a boolean value (`true` or `false`).

### Difference between `==` and `===`

This is an important concept in JavaScript.

`==` compares values only.

```plaintext
console.log(10 == "10");
```

Output:

```plaintext
true
```

Because JavaScript converts `"10"` to a number before comparison.

But `===` compares both value and type.

```plaintext
console.log(10 === "10");
```

Output:

```plaintext
false
```

Here:

```plaintext
10   → number
"10" → string
```

Since the types are different, the result is `false`.

For this reason, most developers usually prefer `===` over `==`.

### Logical Operators

Logical operators are used to combine multiple conditions.

Example:

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

console.log(age > 18 && hasID);
```

Output:

```plaintext
true
```

Here both conditions must be true.

Example of **OR operator**:

```plaintext
console.log(age > 18 || age > 60);
```

Output:

```plaintext
true
```

The OR operator returns true if at least one condition is true.

Example of **NOT operator**:

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

Output:

```plaintext
false
```

The NOT operator simply reverses the boolean value.

### Assignment Operators

Assignment operators are used to **assign values to variables**.

The most common assignment operator is:

```plaintext
=
```

Example:

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

JavaScript also provides shorter assignment operators.

Example:

```plaintext
let x = 10;

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

Output:

```plaintext
15
```

This is equivalent to writing:

```plaintext
x = x + 5;
```

Another example:

```plaintext
let y = 20;

y -= 5;

console.log(y);
```

Output:

```plaintext
15
```

* * *

### Summary

Operators are an essential part of JavaScript programming. They allow us to perform mathematical calculations, compare values, combine conditions, and assign values to variables.

Understanding different types of operators such as **arithmetic operators, comparison operators, logical operators, and assignment operators** helps us write more powerful and expressive programs. As you continue learning JavaScript, you will use operators frequently in conditions, loops, and many other programming scenarios.
