JavaScript Operators: A Complete Tutorial

4/13/2025

#JavaScript Operars: A Complete Tutorial

Go Back

JavaScript Operators: A Complete Tutorial

Operators in JavaScript are symbols used to perform operations on values and variables. They are fundamental to building expressions and implementing logic in your code. In this tutorial, we’ll cover the various types of JavaScript operators with examples.


 #JavaScript Operars: A Complete Tutorial

1. Arithmetic Operators

These are used to perform basic mathematical operations:

OperatorDescriptionExampleResult
+Addition5 + 38
-Subtraction5 - 32
*Multiplication5 * 315
/Division6 / 23
%Modulus (Remainder)5 % 21
**Exponentiation2 ** 38
++Incrementa++a = a + 1
--Decrementa--a = a - 1

2. Assignment Operators

These are used to assign values to variables.

OperatorExampleEquivalent To
=x = 10Assign 10 to x
+=x += 5x = x + 5
-=x -= 3x = x - 3
*=x *= 2x = x * 2
/=x /= 4x = x / 4
%=x %= 2x = x % 2
**=x **= 2x = x ** 2

3. Comparison Operators

These compare two values and return a Boolean (true or false).

OperatorDescriptionExampleResult
==Equal to (loose)5 == '5'true
===Equal to (strict)5 === '5'false
!=Not equal (loose)5 != '5'false
!==Not equal (strict)5 !== '5'true
>Greater than5 > 3true
<Less than5 < 3false
>=Greater than or equal5 >= 5true
<=Less than or equal5 <= 4false

4. Logical Operators

Used to combine conditional statements.

OperatorDescriptionExampleResult
&&Logical ANDtrue && falsefalse
` `Logical OR
!Logical NOT!truefalse

5. String Operators

JavaScript uses the + operator to concatenate strings.

let greeting = "Hello" + " " + "World"; // "Hello World"

You can also use += to append strings:

let name = "John";
name += " Doe"; // "John Doe"

6. Type Operators

typeof

Returns the type of a variable.

typeof "hello"; // "string"
typeof 42;      // "number"

instanceof

Checks if an object is an instance of a specific class.

let date = new Date();
console.log(date instanceof Date); // true

7. Bitwise Operators

These perform operations on binary representations of numbers.

OperatorNameExample
&AND5 & 1
``OR
^XOR5 ^ 1
~NOT~5
<<Left shift5 << 1
>>Right shift5 >> 1

Final Thoughts

JavaScript operators are powerful tools for building logic, manipulating data, and controlling program flow. Mastering them is crucial for any developer looking to write clean and efficient JavaScript code.

Practice combining these operators in real examples and you'll quickly become comfortable using them in your projects!

Table of content