What Are JavaScript Operators? See Examples

JavaScript operators are special symbols used to perform operations on values, variables, and expressions. They help you perform tasks like addition, comparison, assignment, and logical decision-making.

Operators are one of the most essential fundamentals every JavaScript learner must understand before moving to advanced concepts.

This blog explains all major types of operators with clear examples.


1. Arithmetic Operators

Used for mathematical calculations.

OperatorDescriptionExample
+Addition5 + 27
-Subtraction5 - 23
*Multiplication5 * 210
/Division10 / 25
%Modulus (Remainder)10 % 31
**Exponentiation2 ** 38

Example:

let a = 10;
let b = 3;

console.log(a + b); // 13
console.log(a % b); // 1
console.log(a ** b); // 1000

2. Assignment Operators

Used to assign values to variables.

OperatorMeaningExample
=Assignx = 10
+=Add & assignx += 5 (x = x + 5)
-=Subtract & assignx -= 5
*=Multiply & assignx *= 3
/=Divide & assignx /= 2

Example:

let x = 10;
x += 5;  
console.log(x); // 15

3. Comparison Operators

Used to compare values.
They return true or false.

OperatorDescriptionExample
==Equal to5 == "5" → true
===Strict equal (type + value)5 === "5" → false
!=Not equal5 != 3 → true
!==Strict not equal5 !== "5" → true
>Greater than10 > 5 → true
<Less than3 < 8 → true
>=Greater or equal5 >= 5 → true
<=Less or equal3 <= 2 → false

Example:

console.log(5 == "5");  // true
console.log(5 === "5"); // false

4. Logical Operators

Used in decision-making with conditions.

OperatorMeaningExample
&&ANDboth must be true
``
!NOTreverses value

Example:

let age = 20;
console.log(age > 18 && age < 30); // true
console.log(age < 18 || age > 25); // false
console.log(!true); // false

5. String Operators

The + operator can combine (concatenate) strings.

let first = "Hello";
let second = "World";
console.log(first + " " + second);
// Hello World

6. Unary Operators

Single value operations.

OperatorDescriptionExample
++Incrementx++
--Decrementx--
typeofReturns data typetypeof "hello"

Example:

let x = 5;
x++;
console.log(x); // 6

console.log(typeof x); // number

7. Ternary Operator

Short-form of an if-else.

Syntax:

condition ? valueIfTrue : valueIfFalse

Example:

let age = 18;
let message = age >= 18 ? "Adult" : "Minor";
console.log(message); // Adult

Final Thoughts

JavaScript operators are the building blocks for logic, calculations, decisions, and expressions. Mastering them is essential before moving to functions, loops, objects, or advanced topics.


🔗 View other articles about Javascript:

https://savanka.com/category/learn/js

🔗 External Javascript Documentation:

https://www.w3schools.com/js

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *