DevAcademy
LearnJavaScriptJavaScript Operators
BeginnerJavaScript

JavaScript Operators

Learn JavaScript operators with practical examples. Understand arithmetic, assignment, comparison, logical, and increment/decrement operators used in everyday JavaScript programming.

Reading Time

18 min

Lesson

Lesson 7 of 48

What are Operators?

Operators are special symbols that perform operations on values and variables. They allow you to calculate values, compare data, assign variables, and evaluate logical conditions. Operators are one of the most commonly used features in JavaScript.

Why are Operators Important?

Without operators, JavaScript cannot perform calculations or make decisions. Whether you're creating a calculator, validating forms, or checking conditions, operators are used everywhere.

Types of JavaScript Operators

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • Logical Operators
  • Increment & Decrement Operators
  • String Operators

Arithmetic Operators

Arithmetic operators are used to perform mathematical calculations.

Arithmetic Operators Table

OperatorDescriptionExample
+Addition5 + 2
-Subtraction5 - 2
*Multiplication5 * 2
/Division10 / 2
%Remainder10 % 3
**Exponentiation2 ** 3

Arithmetic Operators Example

Try it yourself — edit and run

Console Output

Click “Run” to see the console output here.

Assignment Operators

Assignment operators assign or update values stored in variables.

Assignment Operators Table

OperatorMeaning
=Assign
+=Add and Assign
-=Subtract and Assign
*=Multiply and Assign
/=Divide and Assign
%=Modulus and Assign

Assignment Operator Example

Try it yourself — edit and run

Console Output

Click “Run” to see the console output here.

Comparison Operators

Comparison operators compare two values and always return either true or false.

Comparison Operators Table

OperatorDescription
==Equal
===Strict Equal
!=Not Equal
!==Strict Not Equal
>Greater Than
<Less Than
>=Greater Than or Equal
<=Less Than or Equal

Comparison Example

Try it yourself — edit and run

Console Output

Click “Run” to see the console output here.

Remember

Always prefer === instead of == because === compares both value and data type.

Logical Operators

Logical operators are used to combine multiple conditions.

Logical Operators Table

OperatorDescription
&&AND
||OR
!NOT

Logical Operator Example

Try it yourself — edit and run

Console Output

Click “Run” to see the console output here.

Increment & Decrement

Increment (++) increases a value by one, while decrement (--) decreases a value by one.

Increment Example

Try it yourself — edit and run

Console Output

Click “Run” to see the console output here.

Prefix vs Postfix

The prefix operator (++value) increments the value before it is used, while the postfix operator (value++) uses the current value first and increments it afterward.

Prefix vs Postfix Example

Try it yourself — edit and run

Console Output

Click “Run” to see the console output here.

String Concatenation Operator

The + operator is also used to join strings together.

String Example

Try it yourself — edit and run

Console Output

Click “Run” to see the console output here.

Common Mistake

The + operator joins strings, while -, *, and / automatically convert strings into numbers when possible.

Example

Try it yourself — edit and run

Console Output

Click “Run” to see the console output here.

Best Practice

Use strict equality (===) for comparisons and use parentheses to make complex expressions easier to read.

Summary

JavaScript provides different categories of operators for arithmetic calculations, assignments, comparisons, logical operations, and string concatenation. Mastering these operators is essential before learning conditionals and loops.

Interview Questions

Quick Quiz

1. Which operator compares both value and type?

2. What is the output of 10 % 3?

3. What is the output of "5" + 2?