Operator In Javascript

In this article, we are going to explore and cover up all the operator used in javascript.
Operator
Operator is a symbol used to perform the operation on one or more operand (value and variable) in javascript and return result. Operators are fundamental for performing calculations, comparisons, assignments, and controlling program flow.
Assignment Operator
Assignment operator (=) used to assign value to the variable
for eg
// Javascript keyword (let, const, var)
// let name_of_variable = value
let num = 2026
let name = "Js programming"
the left side is a name of the variable and the value which is on the right side is value is assigned into the variable.
Addition Assignment Operator
this operator is a shorthand notation for writing the addition operator along with assignment operator
// Method 1
var result = 10
result = result + 10
console.log(result) // 20
// Method 2
var result_1 = 10
// name_of_declared_variable += value (which you want to add)
result += 10
console.log(result) // 20
Subtraction Assignment Operator
this operator is a shorthand notation for writing the substraction operator along with assignment operator
// Method 1
var result = 10
result = result - 10
console.log(result) // 20
// Method 2
var result_1 = 10
// name_of_declared_variable -= value (which you want to add)
result -= 10
console.log(result) // 20
Arithmetic Operators
Arithmetic operators is used to perform operation like addition (+), subtraction (-), multiplication (*), division (/), Modular (%), increment (++) and decrement (--).
Addition (+)
Addition operator is used to add one and more operand together. Here are some example.
// Example 1
var result = 10 + 7
console.log(result) // 17
// Example 2
let num1 = 10
let num2 = 20
var result_1 = num1 + num2
console.log(result_1) // 30
Subtraction (-)
subtraction is used to subtract one and more operand together. Here are some of the example of the Subtraction.
// Example 1
var result = 10 - 7
console.log(result) // 3
// Example 2
let num1 = 20
let num2 = 10
var result_1 = num1 - num2
console.log(result_1) // 10
Multiplication (*)
Multiplication is used to multiply one and more operand together. Here are some of the example of the Multiplication.
// Example 1
var result = 10 * 7
console.log(result) // 70
// Example 2
let num1 = 10
let num2 = 20
var result_1 = num1 * num2
console.log(result_1) // 200
Division (/)
Division is used to divided one and more operand together. Here are some of the example of the Division.
// Example 1
var result = 10 / 7
console.log(result) // 1.4285714285714286
// Example 2
let num1 = 10
let num2 = 20
var result_1 = num1 / num2
console.log(result_1) // 0.5
console.log(10/0) // Infinity
Increment (++)
We can use increment operator in two ways
Post Increment operator
Pre Increment operator
Post Increment operator
In this operator the value is increase after the operation is execute.
let result = 10
console.log(result ++) // 10
// After this operation the value of the result is 11
// this result ++ is a short hand for the result = result + 1
// And
// result += 1
Pre Increment operator
In this operator, the value is first increment before the operation has taken place
let result = 10
console.log(++result) // 11
// this ++ result is a short hand for the result = result + 1
// And
// result += 1
Decrement (--)
We can use decrement operator in two ways
Post decrement operator
Pre decrement operator
Post Decrement operator
In this operator the value is increase after the operation is execute.
let result = 10
console.log(result --) // 10
// this result -- is a short hand for the result = result - 1
// And
// result -= 1
Pre Decrement operator
In this operator, the value is first decrement before the operation has taken place
let result = 10
console.log(--result) // 9
// this --result is a short hand for the result = result - 1
// And
// result -= 1
Modular Operator
Modular operator is a division remainder based operator used to get the remainder of two values.
// Example 1
let result = 16 % 2
console.log(result) // 0
// Example 2
let result_2 = 17 % 2
console.log(result_2) // 1
Comparison Operator
comparison operator is used for making the comparison between the variable are as follow.
operator | Description | Comparison | Return |
|---|---|---|---|
== | equal to | "8" == 8 | false |
=== | equal value | 5 === 5 | true |
!= | not equal | 5 != 8 | true |
!== | not equal value | "5" !== 8 | false |
> | greater than | 8 > 5 | true |
< | less than | 5 < 8 | true |
>= | greater than and equal | 5 >= 8 | false |
<= | less than and equal | 5 <= 8 | true |
Equal to (==) vs Equal value (===)
the equal to operator performs type coercion before comparison. JavaScript converts operands to a common type, then compares values. This can lead to unexpected results.
it give true at 5 == "5"
but equal value operator compares both value and type without coercion. Returns true only if both operands are of the same type and have the same value.
it give true only at "5" === "5" otherwise it result in false
Logical Operator
Logical operator are used to combine or modify boolean values to control program flow based on conditions.
// Example 1
let age = 10
if(age > 18){
console.log("You are under age")
}
else if (age > 9 && age < 17 ) {
console.log("you are teen")
}
else console.log("you are child")
Final word
JavaScript operators are fundamental for performing operations on values and variables. They include arithmetic (e.g., +, -, *, /, %), assignment (e.g., =, +=, -=), comparison (e.g., ==, ===, >, <), logical (e.g., &&, ||, !), bitwise, ternary, and nullish coalescing (??) operators.
Understanding operator precedence is crucial: operations like multiplication (*) and division (/) are evaluated before addition (+) and subtraction (-). For example, 3 + 5 * 2 evaluates to 13, not 16, due to precedence rules. Use parentheses to override default precedence and control evaluation order.
Short-circuit evaluation applies to logical operators (&&, ||, ??): if the result can be determined from the first operand, the second is not evaluated. For instance, false || alert("test") will not execute the alert, but true || alert("test") will skip the second part entirely.
The nullish coalescing operator (??) is preferred over || when assigning defaults, as it only returns the right-hand value if the left is null or undefined, preserving valid falsy values like 0, '', or false.
Finally, strict equality (===) avoids type coercion, making it safer than loose equality (==). Always prefer === to prevent unexpected results when comparing values of different types.
Reference
W3Schools :- https://www.w3schools.com/js/default.asp






