What are the Most Common JavaScript Operators?

What are the Most Common JavaScript Operators?

In this article, you will learn about different operators available in JavaScript and how to use them with the help of examples.

What is an Operator?

An operator is a special symbol in JavaScript that is used to perform operations on operands (values and variables).


4 + 4; // 8

Here + is an operator that performs addition, and 4 and 4 are operands.

JavaScript Operator Types

Here is a list of different operators you will learn in this tutorial.

  • Assignment Operators
  • Arithmetic Operators
  • Comparison Operators
  • Logical Operators
  • String Operators

JavaScript Assignment Operators

Assignment operators are used to assign values to variables.


let x = 10;

Here, the = operator is used to assign a value of 10 to variable x.

Here’s a list of commonly used assignment operators:

=Assignment operatorx = y
+=Addition assignmentx += y
-=Subtraction Assignmentx -= y
*=Multiplication Assignmentx *= y
/=Division Assignmentx /= y
%=Remainder Assignmentx %= y

Note: The most commonly used assignment operator is =.

JavaScript Arithmetic Operators

Arithmetic operators are used to perform arithmetic calculations. A typical arithmetic operation operates on two numbers.


let x = 30 + 50;
// x = 80

Arithmetic operators perform arithmetic on numbers (literals or variables). Here’s a list of commonly used arithmetic operators:

+Addition35 + 5 = 35
Subtraction35 – 5 = 20
*Multiplication 10 * 20 = 200
/Division20 / 2 = 10
%Modulus56 % 3 = 2
++Incrementlet a = 10; a++; Now a =11
– –Decrementlet a = 10; a–; Now a = 9

JavaScript Comparison Operators

Comparison operators compare two values and return a boolean value, either true or false. You can check all types of data; comparison operators always return true or false.


const a = 4, b = 2;
console.log(a > b); // true 

Here, the comparison operator > is used to compare whether a is greater than b.

Here’s a list of commonly used comparison operators:

==Equal to5 == 10 false
===Identical (equal and of same type)5 === 10 false
!=Not equal to5 != 10 true
!==Not identical10 !== 10 false
>Greater than10 > 5 true
>=Greater than or equal10 >= 5 true
<Less than10 < 5 false
<=Less than or equal to10 <= 5 false

Note: When using operators, be sure that the arguments are of the same data type; numbers should be compared with numbers, strings with strings, and so on.

JavaScript Logical Operators

Logical operators, also known as Boolean operators, perform logical operations and return a boolean value, either true or false.


(4 > 2) && (10 < 15)

For this expression to be true, both conditions must be true.

  • The first condition determines whether 4 is greater than 2, which is true.
  • The second condition determines whether 10 is less than 15, which is also true.
  • Based on these results, the whole expression is found to be true.

Here’s a list of commonly used logical operators:

&&Logical AND: true if both the operands are true, else returns truex && y
!!Logical OR: true if either of the operands is true; returns false if both are falsex !! y
!Logical NOT: true if the operand is false and vice-versa.!x

Note: You can check all types of data; comparison operators always return true or false.

JavaScript String Operators

The most useful operator for strings is concatenation, represented by the + sign.
Concatenation can be used to build strings by joining together multiple strings, or by joining strings with other types.


let string1 = "I am learning";
let string2 = "JavaScript.";
let string3 = string1 + " " + string2;
//I am learning JavaScript.

The above example declares and initialises two string variables, and then concatenates them.

Note: When + is used with strings, it performs concatenation. However, when + is used with numbers, it performs addition.


let x = 6 + 6;
let y = "6" + 6;
let z = "Hello" + 88;
/* Output

Note: Numbers in quotes are treated as strings. And If you add a number and a string, the result will be a string!


In this article, we learned about JavaScript operators and their various types. Operators perform arithmetic operations, assign or compare values, evaluate expressions, and more.

Further reading

Want to learn more about JavaScript Operators? Expressions and operators – JavaScript | MDN

See also

How to Comment Code in JavaScript – Best Practices
What are the Three Variables in JavaScript?
What are the Three Primitive JavaScript Data Types?

If you liked this article, then please share. You can also find me on Twitter for more updates.

Pin It on Pinterest