JavaScript Operators (with Examples)

Operator and operands are two keywords used in programming to perform multiple types of operation, this operation can be of different types such as addition, subtraction, multiplication, division, etc. 

The operands are the entity to which the operation is performed. In contrast, the operators are the entity that performs that operation and decides the operation type, for example, the + operator performs addition whereas the – operator performs subtraction.

JavaScript has multiple types of operators, in this tutorial we have covered them with easy examples so that you don’t have to scratch your brain to understand them.

Types of Operators in JavaScript:

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • Logical Operators
  • typeof Operator
  • Ternary Operator

JavaScript Arithmetic Operators

Arithmetic Operators are the operator used to perform arithmetic operations. The arithmetic operation included addition(+), subtraction(-), multiplication(*), division(/), modulus(%), increment(++), and decrement(–).



let x = 1;
let y = 2;

let z = x + y;

console.log("Addition: " + z);

Here, we have initialised two variables with some values and then use the + operator to perform addition and print the output in the console.


Addition: 3

JavaScript Assignment Operators

Assignment Operators are used to assign value to a variable. JavaScript has many assignment operators that can perform arithmetic operators and then assign the given value such as Add and Assign, which first adds the value and then assign it.

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


let x = 2;
let y = x; // assign value of x to y


y += y; // add y then assign total value to y


Here we have used the = operator to assign the value of x to y, then used the += operator which first adds the current value of y to itself and then assigns it to itself.



JavaScript Comparison Operators

Comparison Operators are used to comparing two values(i.e. operands). There can be multiple ways someone checks for a comparison. JavaScript has many comparison operators that can perform basic to advance level comparisons.

!=Not Equal
===Strict equal
!==Not Strict equal
>Greater than
>=Greater than or equal to
<Less than
<=Less than or equal to


let x = 2;
let y = 3;

let compare = (x < y);


Here we have compared two variables x and y using the < operator, which returns true if the value of x is smaller than y, and returns false if it is not.



JavaScript Logical Operators

Logical Operators are used to perform logical AND, OR and NOT operations.

||Logical OR
&&Logical AND
!Logical NOT


let x = true;
let y = false;

let result = x && y;


Here we have used && operator which returns true only if both side values are equal, if not then returns false.



JavaScript typeof Operator

This operator is used to get the type of a variable.


let x = 2;

let type = typeof x;




Want to get the type of Object as well? Don’t worry we have a separate tutorial on it, consider reading it.

JavaScript Ternary Operator

The ternary operator is used for conditional execution. It separates a condition and two expressions with a question mark (?), and the two expressions are also separated with a colon (:), it first checks for the condition, if true then executes the first expression and, if false then executes the second expression.


let x = 2;
let y = 3;

let ternaryOperator = x < y ? "x is less than y" : "x is greater than y";



x is less than y


Operators in JavaScript are used to perform different types of operations on operands. In programming, we perform many operations, JavaScript operator helps exactly to do so. You can perform literally any type of operation in JavavScript using the operator we have discussed above. Hope you find this tutorial useful.


Aditya Gupta
Aditya Gupta
Articles: 119