# Understanding JavaScript Operations: A Complete Guide

# Operations

In JavaScript, various operations allow us to perform calculations and manipulate data effectively. These operations are executed using **operators**, which act on **operands** to carry out the desired tasks.

## What Are Operators and Operands?

* **Operands**: The values or variables on which an operation is performed.
    
* **Operators**: Symbols or keywords that denote the operation to be performed, such as addition or multiplication.
    

### Example:

If we have two variables, `a` and `b`:

* `a` and `b` are **operands**.
    
* `+` is the **operator**, performing the addition operation.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1735436473998/8d46c5bc-b6b4-49d0-90b8-7c4bd5605cdf.png align="center")

**Operands :** Operands mean the entities on which operations are being [performed.](http://performed.Plus)

[**Plus**](http://performed.Plus) **is our operator :** Operator means the one that will perform the operation (in this case, the operation being performed is addition).

**Operation means any work that is being performed.**

## Types of Operations

### 1\. Addition (`+`)

The addition operator sums two operands.

#### Example:

```javascript
let a = 10;
let b = 5;
let sum = a + b;
console.log(sum); // Output: 15
```

---

### 2\. Subtraction (`-`)

The subtraction operator calculates the difference between two operands.

#### Example:

```javascript
let a = 10;
let b = 5;
let difference = a - b;
console.log(difference); // Output: 5
```

---

### 3\. Multiplication (`*`)

The multiplication operator multiplies two operands.

#### Example:

```javascript
let a = 10;
let b = 5;
let product = a * b;
console.log(product); // Output: 50
```

---

### 4\. Division (`/`)

The division operator divides the first operand by the second.

#### Example:

```javascript
let a = 10;
let b = 5;
let quotient = a / b;
console.log(quotient); // Output: 2
```

---

### 5\. Modulo (`%`)

The modulo operator calculates the remainder of the division between two numbers.

#### Example:

```javascript
let a = 10;
let b = 3;
let remainder = a % b;
console.log(remainder); // Output: 1
```

### Use of Modulo for Odd and Even Numbers

* **Odd Numbers**: A number is odd if `number % 2` is not equal to 0.
    
* **Even Numbers**: A number is even if `number % 2` equals 0.
    

#### Example:

```javascript
let number = 7;
if (number % 2 === 0) {
  console.log("Even");
} else {
  console.log("Odd");
}
```

---

### 6\. Exponentiation (`**`)

The exponentiation operator raises the first operand to the power of the second.

#### Syntax:

```javascript
let result = base ** exponent;
```

#### Example:

```javascript
let base = 2;
let exponent = 3;
console.log(base ** exponent); // Output: 8
```

* **Modulo is most commonly used in JavaScript to detect odd and even numbers.**
    
* **With the help of the modulo operator, we can determine which number is {odd} and which is {even}.**
    

## Odd and Even

**Odd: Whenever we perform a modulo operation of any number (n) with 2,**

**The number will not be completely divisible by 2 and there will always be some remainder left.**

If our odd number is not completely divisible by 2 and the remainder left is {**something different from zero**},

> **This means our number becomes odd.**

* **And any number that is not completely divisible by 2 {with a remainder different from zero} is considered an odd number.**
    

**Even: Whenever we perform a modulo operation of any number (n) with 2 and the result is zero,**

**Example: We take any number, divide by 2, and if the remainder is zero, it means it is completely divisible.**

* **And any number that is completely divisible by 2 is considered an even number.**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1735437097329/f224fb6f-896e-41fa-9a02-012bcaa53b76.png align="left")
    
    ## **Exponentiation (Power Operator)**
    
    **The exponentiation power operator is used when we need to calculate one number raised to the power of another number.**
    
    ## **Syntax**
    
    ### **2\*\*3 = 8** Explain - This means (2 \\times 2 \\times 2 = 8)
    
    This expression explains that when 2 is raised to the power of 3, it is equivalent to multiplying 2 by itself three times, which results in 8.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1735437303135/2ebd16a6-6931-4c53-95a8-ebf61acc9ab8.png align="center")
