TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript operators

JavaScript operator are symbol that operates the operands. JavaScript includes various categories of operators: Arithmetic, Comparison and logical operators etc.

<< Back to JAVASCRIPT

JavaScript Operators

JavaScript operators are symbols that are used to perform operations on operands. For example:

var sum=10+20;

Here, + is the arithmetic operator and = is the assignment operator.

There are following types of operators in JavaScript.

  1. Arithmetic Operators
  2. Comparison (Relational) Operators
  3. Bitwise Operators
  4. Logical Operators
  5. Assignment Operators
  6. Special Operators

JavaScript Arithmetic Operators

Arithmetic operators are used to perform arithmetic operations on the operands. The following operators are known as JavaScript arithmetic operators.

OperatorDescriptionExample
+Addition10+20 = 30
-Subtraction20-10 = 10
*Multiplication10*20 = 200
/Division 20/10 = 2
%Modulus (Remainder)20%10 = 0
++Incrementvar a=10; a++; Now a = 11
--Decrementvar a=10; a--; Now a = 9

JavaScript Comparison Operators

The JavaScript comparison operator compares the two operands. The comparison operators are as follows:

OperatorDescriptionExample
==Is equal to10==20 = false
===Identical (equal and of same type)10==20 = false
!=Not equal to10!=20 = true
!==Not Identical 20!==20 = false
>Greater than20>10 = true
>=Greater than or equal to20>=10 = true
<Less than20<10 = false
<=Less than or equal to20<=10 = false

JavaScript Bitwise Operators

The bitwise operators perform bitwise operations on operands. The bitwise operators are as follows:

OperatorDescriptionExample
&Bitwise AND(10==20 & 20==33) = false
|Bitwise OR(10==20 | 20==33) = false
^Bitwise XOR(10==20 ^ 20==33) = false
~Bitwise NOT (~10) = -10
<<Bitwise Left Shift(10<<2) = 40
>>Bitwise Right Shift(10>>2) = 2
>>>Bitwise Right Shift with Zero(10>>>2) = 2

JavaScript Logical Operators

The following operators are known as JavaScript logical operators.

OperatorDescriptionExample
&&Logical AND(10==20 && 20==33) = false
||Logical OR(10==20 || 20==33) = false
!Logical Not!(10==20) = true

JavaScript Assignment Operators

The following operators are known as JavaScript assignment operators.

OperatorDescriptionExample
=Assign10+10 = 20
+=Add and assignvar a=10; a+=20; Now a = 30
-=Subtract and assignvar a=20; a-=10; Now a = 10
*=Multiply and assignvar a=10; a*=20; Now a = 200
/=Divide and assignvar a=10; a/=2; Now a = 5
%=Modulus and assignvar a=10; a%=2; Now a = 0

JavaScript Special Operators

The following operators are known as JavaScript special operators.

OperatorDescription
(?:)Conditional Operator returns value based on the condition. It is like if-else.
,Comma Operator allows multiple expressions to be evaluated as single statement.
deleteDelete Operator deletes a property from the object.
inIn Operator checks if object has the given property
instanceofchecks if the object is an instance of given type
newcreates an instance (object)
typeofchecks the type of object.
voidit discards the expression's return value.
yieldchecks what is returned in a generator by the generator's iterator.




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf