JavaScript Operators Explained with Examples
Web Development

JavaScript Operators Explained with Examples

21 Sep, 2026 CCI Admin Web Development
Back to All Blogs

JavaScript Operators Explained with Examples

Published: 21 Sep, 2026 | Author: CCI Admin | Category: JavaScript / Web Development

JavaScript operators are symbols used to perform operations on values and variables. They are an important part of JavaScript programming and are used in calculations, comparisons, logical decisions, and many real-world web applications.

In this blog, we will learn the commonly used JavaScript operators with simple examples.

What Are Operators in JavaScript?

An operator performs an operation on one or more values. For example, the + operator can be used to add two numbers.

let a = 10;
let b = 5;

let result = a + b;

console.log(result);

Output:

15

Types of JavaScript Operators

JavaScript provides several types of operators:

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • Logical Operators
  • Increment and Decrement Operators
  • Conditional (Ternary) Operator

1. Arithmetic Operators

Arithmetic operators are used to perform mathematical calculations.

Operator Meaning Example
+ Addition 10 + 5 = 15
- Subtraction 10 - 5 = 5
* Multiplication 10 * 5 = 50
/ Division 10 / 5 = 2
% Remainder 10 % 3 = 1
** Exponentiation 2 ** 3 = 8

Example

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);

2. Assignment Operators

Assignment operators are used to assign values to variables.

Operator Example Meaning
= x = 10 Assigns 10 to x
+= x += 5 x = x + 5
-= x -= 5 x = x - 5
*= x *= 5 x = x * 5
/= x /= 5 x = x / 5

Example

let score = 50;

score += 10;

console.log(score);

Output:

60

3. Comparison Operators

Comparison operators are used to compare two values. The result of a comparison is usually true or false.

Operator Meaning Example
== Equal value 5 == "5"
=== Equal value and type 5 === 5
!= Not equal value 5 != 3
!== Not equal value or type 5 !== "5"
> Greater than 10 > 5
< Less than 5 < 10
>= Greater than or equal 10 >= 10
<= Less than or equal 5 <= 10

Example

let age = 20;

console.log(age >= 18);

Output:

true

4. Logical Operators

Logical operators are used to combine multiple conditions.

Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT

Example

let age = 25;
let hasID = true;

if (age >= 18 && hasID) {
    console.log("Access Granted");
} else {
    console.log("Access Denied");
}

Output:

Access Granted

5. Increment and Decrement Operators

The increment operator ++ increases a value by 1, while the decrement operator -- decreases a value by 1.

Example

let count = 5;

count++;

console.log(count);

count--;

console.log(count);

Output:

6
5

6. Conditional (Ternary) Operator

The ternary operator provides a short way to write a simple if-else condition.

Example

let age = 20;

let result = age >= 18 ? "Adult" : "Minor";

console.log(result);

Output:

Adult

Real-Time Example – Student Result

JavaScript operators can be combined to create simple real-world applications such as a student result checker.

let mark = 75;

if (mark >= 50) {
    console.log("Student Passed");
} else {
    console.log("Student Failed");
}

Output:

Student Passed

Why Are JavaScript Operators Important?

  • They help perform mathematical calculations.
  • They allow programmers to compare values.
  • They help create decision-making logic.
  • They are used in loops and conditions.
  • They are essential for developing interactive websites.
  • They are widely used in JavaScript web applications.

Important Points to Remember

  • Use arithmetic operators for calculations.
  • Use assignment operators to store or update values.
  • Use comparison operators to compare values.
  • Use logical operators to combine conditions.
  • Use === when you want to compare both value and type.
  • Use the ternary operator for simple conditional expressions.

FAQ – JavaScript Operators

What are operators in JavaScript?

Operators are symbols used to perform operations on values and variables in JavaScript.

What is the difference between == and ===?

The == operator compares values with type conversion when necessary, while === compares both value and data type without type conversion.

What is the use of && in JavaScript?

The && operator represents logical AND. It is used when multiple conditions need to be true.

What is the ternary operator?

The ternary operator is a short form of a simple if-else statement. Its syntax is:

condition ? valueIfTrue : valueIfFalse;

Where are JavaScript operators used?

JavaScript operators are used in calculations, comparisons, conditions, loops, forms, validation, web applications, and many other programming tasks.

Conclusion

JavaScript operators are fundamental building blocks of JavaScript programming. Understanding arithmetic, assignment, comparison, logical, increment, decrement, and ternary operators helps beginners write better and more interactive programs.

By practicing these operators with simple programs, students can build a strong foundation for learning JavaScript and web development.

Learn JavaScript and Web Development with practical training at CCI Computer Education, Pudukkottai.


Related CCI Blogs



Contact CCI Computer Education – Pudukkottai

Want to learn JavaScript, Web Development, and other programming skills through practical training?

Call: 98427 97945  |  Website: ccipudukkottai.com

WhatsApp Channel: Join Now

Share: Facebook | WhatsApp | Twitter