Back to blog
JavaScript

JavaScript Operators: The Basics You Need to Know

May 14, 2026 3 min read

What Are Operators?

Operators perform actions on values.

Examples:

  • Addition

  • Comparison

  • Checking conditions

  • Assigning values


Arithmetic Operators

Used for mathematical calculations.


Arithmetic Operators Table

OperatorPurpose
+Addition
-Subtraction
*Multiplication
/Division
%Remainder

Addition

const a = 10;
const b = 5;

console.log(a + b);


Output

15


Subtraction

console.log(10 - 5);


Output

5


Multiplication

console.log(4 * 3);


Output

12


Division

console.log(20 / 4);


Output

5


Modulus %

Returns remainder.

console.log(10 % 3);


Output

1


Comparison Operators

Used to compare values.

Result is always:

true or false


Comparison Operators Table

OperatorMeaning
==Equal
===Strict equal
!=Not equal
>Greater than
<Less than

Equal ==

Checks value only.

console.log(5 == "5");


Output

true

JavaScript converts types automatically.


Strict Equal ===

Checks:

  • Value

  • Data type

console.log(5 === "5");


Output

false


== vs ===

OperatorChecks
==Value only
===Value + type

Recommendation

Prefer:

===

because it avoids unexpected type conversion.


Not Equal !=

console.log(10 != 5);


Output

true


Greater Than and Less Than

console.log(10 > 5);

console.log(3 < 8);


Output

true
true


Logical Operators

Used to combine conditions.


Logical Operators Table

OperatorMeaning
&&AND
` 
!NOT

AND Operator &&

Returns true only if both conditions are true.

const age = 20;
const hasID = true;

console.log(age >= 18 && hasID);


Output

true


OR Operator ||

Returns true if at least one condition is true.

console.log(true || false);


Output

true


NOT Operator !

Reverses boolean value.

console.log(!true);


Output

false


Truth Table for Logical Operators

ABA && BA || B
truetruetruetrue
truefalsefalsetrue
falsetruefalsetrue
falsefalsefalsefalse

Assignment Operators

Used to assign or update values.


Assignment Operators Table

OperatorExample
=Assign value
+=Add and assign
-=Subtract and assign

Basic Assignment

let score = 10;


Add and Assign +=

let score = 10;

score += 5;

console.log(score);


Output

15


Subtract and Assign -=

let score = 20;

score -= 5;

console.log(score);


Output

15


Operator Categories Diagram

Diagram: flowchart TD

Practical Example

const age = 20;
const isStudent = true;

if (age >= 18 && isStudent) {
  console.log("Eligible");
}


Output

Eligible


Assignment

1. Arithmetic Operations

const a = 10;
const b = 5;

console.log(a + b);
console.log(a - b);
console.log(a * b);
console.log(a / b);
console.log(a % b);


2. Compare Values

console.log(5 == "5");

console.log(5 === "5");


3. Logical Condition

const age = 22;
const hasLicense = true;

console.log(age >= 18 && hasLicense);


Common Beginner Mistakes

Using == Accidentally

5 == "5"

returns:

true

Use === for safer comparisons.


Confusing % With Percentage

10 % 3

means remainder, not percentage.


Key Takeaways

ConceptSummary
Arithmetic OperatorsPerform math
Comparison OperatorsCompare values
Logical OperatorsCombine conditions
Assignment OperatorsStore/update values
===Safer equality check

Final Notes

Operators are used everywhere in JavaScript:

  • Conditions

  • Calculations

  • Authentication

  • Loops

  • APIs

  • Form validation

Mastering operators is important before learning:

  • Functions

  • Loops

  • Objects

  • Backend logic


0 Comments

Sign in to join the conversation

No comments yet. Be the first to comment!