# JavaScript Operators: The Basics You Need to Know

# What are operators

When we write a programs in JavaScript, we often need to perform calculations, compare values or make decisions. This is where **operators** come into play. Operators are the building blocks of JavaScript expressions and can manipulate data in various ways.

JavaScript provides many types of operators, but in this article we will focus on the most commonly used ones :

![](https://cdn.hashnode.com/uploads/covers/63c43a8adbe7ab4342a06690/618da7ed-67ca-4068-8ef5-52ed18c6a62b.png align="center")

* * *

# Arithmetic operators ( +, - , \* )

Arithmetic Operators are used to perform mathematical calculations like addition, subtraction, multiplication, etc.

## Addition ( + )

```javascript
let a=10;
let b=20;

console.log(a + b);
```

## Subtraction ( - )

```javascript
let a=10;
let b=20;

console.log(a - b);
```

## Multiplication ( \* )

```javascript
let a=10;
let b=20;

console.log(a * b);
```

## Division ( / )

```javascript
let a=10;
let b=20;

console.log(a / b);
```

## Modulus ( % )

The modulus operator returns the remainder after division.

```javascript
let a=10;
let b=3;

console.log(a % b);    // output : 1
```

Why output is 1 ?

Because 10 % 3 = 3 remainder 1

* * *

# Comparison operators

Comparison operators are used to compare two values. This operators returns true or false.

## Equal To ( == )

This checks if values are equal after type conversion.

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

JavaScript converts "5" ( string) into 5 (number).

## Strict Equal To ( === )

This checks values and type both.

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

## Not Equal ( != )

```javascript
console.log(5 != 3); //output: true
```

## Greater Than ( > )

```javascript
console.log(10 > 6); //output: true
```

## Less Than ( < )

```javascript
console.log(10 < 16); //output: true
```

* * *

# Logical operators

Logical operators are mainly used to perform the logical operations that determine the equality or difference between the values. This operators are used when working with conditions.

## AND (&&)

AND logical operators returns true only if both conditions are true.

```javascript
let age = 20;

console.log(age > 18 && age < 30); //output: true
```

## OR (||)

OR Logical operators returns true if at least one condition is true.

```javascript
let age = 20;

console.log(age > 18 || age < 30); //output: true
```

## NOT (!)

NOT logical operators returns the **reverses** of **boolean** value.

```javascript
let isLoggedIn = false;

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

## Truth Table for Logical Operators

![](https://cdn.hashnode.com/uploads/covers/63c43a8adbe7ab4342a06690/f91c7975-6c5d-4e18-b29d-6e6d847b79be.png align="center")

* * *

# Assignment operators

Assignment operators are the sign values to variables.

## Basic Assignment ( = )

```javascript
let x = 10;
```

This line of code assign 10 to variables x .

## Add and Assign (+=)

```javascript
let x=10;

x+=10; 

console.log(x)  // output : 20
```

This is same as writing x=x+10;

## Subtract and Assign (-=)

```javascript
let x=20;

x-=10;

console.log(x) //output: 10
```

This is same as writing as x=x-10;

* * *

# **📌 Wrapping Up**

Thanks for reading till the end 🙌  
I hope this article helped you understand the topic in a simple, practical, and beginner-friendly way.

My goal is to break down complex tech concepts into clear, real-world explanations, especially for learners who are just starting out or feeling overwhelmed.

If you found this useful, feel free to bookmark, share, or leave a comment - it really helps and keeps me motivated to write more.

You can connect with me here:

*   🐦 [**X (Twitter)**](https://x.com/RahulDe13551305)
    
*   💼 [**LinkedIn**](https://www.linkedin.com/in/devrahulll)
    

Let’s learn together and grow step by step 🚀
