This site uses tracking technologies. You may opt in or opt out of the use of these technologies.

Back to Javascript

Basic operators

In JavaScript, operators are symbols that allow you to perform operations on values and variables.

1. Arithmetic Operators

These operators are used to perform mathematical operations:

OperatorDescriptionExampleResult
+Addition5 + 27
-Subtraction5 - 23
*Multiplication5 * 210
/Division5 / 22.5
%Modulus (Remainder)5 % 21
**Exponentiation (ES6)5 ** 225
++Increment (Add 1)let x = 5; x++6
--Decrement (Subtract 1)let x = 5; x--4

2. Assignment Operators

These operators assign values to variables:

OperatorExampleEquivalent to
=x = 5x = 5
+=x += 5x = x + 5
-=x -= 5x = x - 5
*=x *= 5x = x * 5
/=x /= 5x = x / 5
%=x %= 5x = x % 5
**=x **= 2x = x ** 2

3. Comparison Operators

These operators compare two values and return a boolean (true or false):

OperatorDescriptionExampleResult
==Equal to5 == '5'true
===Strict equal to (type check)5 === '5'false
!=Not equal to5 != '5'false
!==Strict not equal (type check)5 !== '5'true
>Greater than5 > 2true
<Less than5 < 2false
>=Greater than or equal to5 >= 5true
<=Less than or equal to5 <= 2false

4. Logical Operators

These operators are used to perform logical operations:

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

These are the fundamental operators you’ll frequently encounter when writing JavaScript code. They allow you to manipulate and compare data efficiently.