Mastering JavaScript Operators: Examples & Best Practices

Sarah Jul 13, 2026

The JavaScript operator is a fundamental aspect of any programming language, enabling operations on variables and values. Understanding operators in JavaScript is crucial for any developer, as they form the building blocks of programming logic.

JavaScript Logical Operators: Master &&, ||, and ! for Smarter Code 🤖
JavaScript Logical Operators: Master &&, ||, and ! for Smarter Code 🤖

In JavaScript, operators are symbols used to perform operations on values and variables. They can be categorized into several types, including arithmetic, assignment, comparison, logical, and more. Let's delve into the world of JavaScript operators with practical examples.

the operator's manual for programming
the operator's manual for programming

Arithmetic Operators

Arithmetic operators are used to perform mathematical operations in JavaScript.

Operators in JavaScript | Types, Example
Operators in JavaScript | Types, Example

Here are the basic arithmetic operators in JavaScript along with examples:

Operator Description Example
+ Addition let sum = 10 + 5;
- Subtraction let diff = 10 - 5;
* Multiplication let product = 10 * 5;
/ Division let quotient = 10 / 5;
% Modulus (Remainder) let remainder = 10 % 5;
** Exponentiation let power = 10 ** 2;
++ Increment let counter = 10; counter++;
-- Decrement let counter = 10; counter--;
JavaScript Operators.
JavaScript Operators.

Arithmetic vs. Assignment Operators

While the operators above perform arithmetic calculations, assignment operators are used to assign values to JavaScript variables. The most common assignment operator is the equal sign (=).

However, JavaScript also offers compound assignment operators like +=, -=, *=, etc., which combine an arithmetic operation with an assignment. For example:

Comparison operators in JavaScript
Comparison operators in JavaScript

let x = 10;

x += 5;

This is equivalent to:

JavaScript Assignment Operators: Simplify Your Code Efficiently ✅
JavaScript Assignment Operators: Simplify Your Code Efficiently ✅

x = x + 5;

Comparison Operators

JavaScript Operators Part 1
JavaScript Operators Part 1
JavaScript Operators | Simply explained 🚀
JavaScript Operators | Simply explained 🚀
a white board with yellow text on it that says,'javaserpt operators operators are symbols used to perform operations
a white board with yellow text on it that says,'javaserpt operators operators are symbols used to perform operations
Operators
Operators
JavaScript Operators | part 4 | Unary Operator 📚 🚀
JavaScript Operators | part 4 | Unary Operator 📚 🚀
Arithmetic Operators in JavaScript
Arithmetic Operators in JavaScript
The typeof Operator in JavaScript
The typeof Operator in JavaScript
Conditional Operator in JavaScript | Ternary, Example
Conditional Operator in JavaScript | Ternary, Example
Operators and Operator Precedence In JavaScript
Operators and Operator Precedence In JavaScript
JavaScript Increment & Decrement Operators: Simplify Your Code 🔄
JavaScript Increment & Decrement Operators: Simplify Your Code 🔄
JavaScript Comparison Operators: Master == vs === & More! ⚖️
JavaScript Comparison Operators: Master == vs === & More! ⚖️
Assignment Operators
Assignment Operators
JavaScript Conditional Operators: Write Smarter Code with ? : 🚀
JavaScript Conditional Operators: Write Smarter Code with ? : 🚀
JavaScript Operators: Master Arithmetic, Logical & Comparison Ops 🔢
JavaScript Operators: Master Arithmetic, Logical & Comparison Ops 🔢
JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)
JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)
Example use of the spread operator in JavaScript
Example use of the spread operator in JavaScript
the different types of operators are shown in this table listing information for each operator's operating
the different types of operators are shown in this table listing information for each operator's operating
an info sheet with different types of programming
an info sheet with different types of programming
Functions in Javascript
Functions in Javascript
How to use Spread operator and Rest parameter in JavaScript? Example Tutorial
How to use Spread operator and Rest parameter in JavaScript? Example Tutorial

Comparison operators are used to test whether a condition is true or false in JavaScript.

Here are the comparison operators in JavaScript:

Operator Description Example
== Equal to let x = 10; x == 10;
!= Not equal to let x = 10; x != 10;
=== Identical to (equals with same type) let x = 10; x === 10;
!== Not identical to let x = 10; x !== '10';
> Greater than let x = 10; x > 5;
< Less than let x = 10; x < 5;
>= Greater than or equal to let x = 10; x >= 5;
<= Less than or equal to let x = 10; x <= 5;

These operators are essential for constructing if-else statements and loops in JavaScript.

Logical Operators

Logical operators are used to test the truth or falsehood of multiple conditions.

Here are the logical operators in JavaScript:

Operator Description Example
&& And (true if all conditions are true) let x = 10; let y = 20; x > 5 && y > 15;
| Or (true if any condition is true) let x = 10; let y = 20; x > 5 || y > 15;
! Not (inverts the boolean value) let x = 10; !(x > 5);

Combining these operators allows for the creation of complex conditional statements.

Bitwise Operators

Bitwise operators manipulate binary representations of integers.

Here are the bitwise operators in JavaScript:

Operator Description Example
& Bitwise AND let a = 60; let b = 13; a & b;
| Bitwise OR let a = 60; let b = 13; a | b;
^ Bitwise XOR let a = 60; let b = 13; a ^ b;
~ Bitwise NOT let a = 60; ~a;
<< Bitwise Left Shift let a = 60; let b = 2; a << b;
>> Bitwise Right Shift let a = 60; let b = 2; a >>> b;
... Zero fill Right Shift (bitwise NOT, then bitwise right shift) let a = 60; let b = 2; a >>> b;

Understanding these operators can help optimize certain operations where boolean logic isn't sufficient.

In conclusion, mastering JavaScript operators is a critical step in becoming a proficient JavaScript developer. These operators form the backbone of JavaScript calculations, comparisons, and logical expressions. Keep practicing and exploring, and soon you'll be writing complex JavaScript code with ease. Happy coding!