In this article we will learn about importance of operators and different categories of operators in JavaScript.
Contents
Introduction
JavaScript supports most of the traditional operators, which are grouped depending on their functionality, as follows:
- Arithmetic Operators
- Assignment Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
Arithmetic Operators
Following are the arithmetic operators in JavaScript:
+ |
– |
* |
/ |
% |
++ |
— |
– (unary) |
+ (unary)
|
Assignment Operators
Following are the assignment operators in JavaScript:
+= |
-= |
*= |
/= |
%= |
<<= |
>>= |
>>>= |
&= |
|= |
^=
|
Relational Operators
Following are the relational operators in JavaScript:
Operator | Operation |
= = | Equal to |
! = | Not equal to |
< | Less than |
< = | Less than or equal to |
> | Greater than |
> = | Greater than or equal to |
= = = | Is strictly equal to |
! = = | Is strictly not equal to |
The = = = and ! = = relational operators considers the type of the operands while evaluating the expression.
Logical Operators
Following are the logical operators in JavaScript:
&& |
|| |
! |
Bitwise Operators
Following are the bitwise operators in JavaScript:
& |
| |
^ |
~ |
<< |
>> |
>>> |
Operator precedence
Below table summarizes the operator precedence and associativity for all the operators in JavaScript:
Operators |
Precedence Level |
Associativity |
. (dot), [ ], new, ( ), ++, — | 1 | Left to right |
++, — | 2 | Right to left |
+ (unary), – (unary), ~, !, delete, typeof, void | 3 | Right to left |
*, /, % | 4 | Left to right |
+, – | 5 | Left to right |
<<, >>, >>> | 6 | Left to right |
<, <=, >, >=, instanceof, in | 7 | Left to right |
==, !=, ===, !== | 8 | Left to right |
& | 9 | Left to right |
^ | 10 | Left to right |
| | 11 | Left to right |
&& | 12 | Left to right |
|| | 13 | Left to right |
?: | 14 | Right to left |
=, *=, /=, %=, +=, -=, <<=, >>=, >>>=, &=, ^= |= | 15 | Right to left |
, (comma) | 16 | Left to right |
String Concatenation Operator
Unlike C, strings in JavaScript are not stored or treated as arrays. Strings in JavaScript are unit scalar values. Two strings can be concatenated with each other using the + operator. For example, if a variable first holds the string value “Java” then the result of the following expression will be JavaScript:
first + “Script”
Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.
He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.
He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.
Leave a Reply