JavaScript Part-4: JavaScript Operators In Details

JavaScript Part-4: JavaScript Operators In Details
Image

What are Arithmetic Operators in JavaScript?

The symbols that are used to do mathematical work are called JavaScript Arithmetic Operators.

All of the following Arithmetic Operator supports JavaScript

To understand the table below, we will take the variable var a = 10 and var b = 5

Operator nameDescriptionExample
+Addition or sum of two operandsa + b = 15 will come
Will give subtraction or subtraction of two operandsa-b = 5 will come
*Multiplication or product of two operandsa * b = 50 will come
/Division or quotient of two operanda / b = 2 will come
%Modulus of the two operand or will give the remainder after sharinga% b = 0 will appear
**The second operand of the two operands will be used as the power of the first operand.2 ** 3 = 8 will come

What are Comparison Operators in JavaScript?

The symbols in JavaScript that are used to compare two variables with one another are called Comparison Operators in JavaScript terminology.

All of the following Comparison Operator supports JavaScript

To understand the table below, we will take the variable var a = 10 and var b = 5

Operator nameDescriptionExample
==Verifies whether the value or value of the two operands is the same, if equal, the result will be true and in all cases the result will be false or no result.  a == b Here the result will be false.
! =Verifies whether the value or value of the two operands is the same, if not equal, the result will be true and in all cases the result will be false or no result.  a! = b Here the result will be true.
===Checks the value of two operands and whether their data type is the same, if both are equal, the result will be true and in all cases the result will be false or no result.  a === b Here the result is false.
! ==Checks the value of two operands and whether their data type is the same, if both or either one is not equal then the result will be true and in all cases the result will be false or no result.  a! == ”10 ″ Here the result will come true.
If the first of the values ​​of the two operands is small, the output or result will be true. And in all cases the result is false or will not give any result  a
If the first of the values ​​of the two operands is large, the output or result will be true. And in all cases the result is false or no result  a> b Here the result will be true.
<=If the first of the values ​​of the two operands is small or equal, the output or result will be true. And in all cases the result is false or no result  a <= b Here the result will be false.
> =If the first of the values ​​of two operands is greater or equal, the output or result will be true. And in all cases the result is false or no result  a> = b Here the result will be true.

What is Assignment Operator in JavaScript?

The symbols used in JavaScript to store a value between Variable or Constant permanently or temporarily is called Assignment Operator in JavaScript.

All of the following Assignment Operator supports JavaScript

To understand the table below, we will take the variable var a = 10 and var b = 5

Operator namedescriptionexample
=Used to assign or save any Operand on the right to the Variable or Constant on the left.  c = a + b; That is, the sum of a and b will be stored in c.  
+ =It is an abbreviation of a = a + b.a + = b; That is, the sum of a and b will again be saved on the left side a.  
– =It is an abbreviation of a = a-b. a- = b;That is, the subtraction of a and b will again store the a on the left.  
* =It is an abbreviation of a = a * b. a * = b;That is, the product of a and b will be saved again on the left side a.  
/ =This is an acronym for a = a / b. a / = b;That is, the quotient of a and b will again be stored in the a on the left.  
% =This is an acronym for a = a% b. a% = b;That is: take out the remainder of a and b and save it in the left side a again.      
** =It is an abbreviation of a = a ** b. a ** = b;That is, the output that gets the power equal to the value of b on a will be saved in variable a again.  
<< =This is an abbreviation of a = a << b. a << = b;That is, the output that is left shift equal to the value of a to b will be saved in variable a again.  
>> =It is an abbreviation of a = >> b. a << = b;That is, the output obtained by right shift equal to the value of a to b will be saved again in variable a.  

What are String Operators in JavaScript?

Symbols or symbols in JavaScript that use the “+” symbol to connect two or more string variables or Strings with Number or just string to one another, in JavaScript terminology it is called String Operators.

Example:

Image

What is the Increment / Decrement Operator in JavaScript?

The (++) symbol is used to increase the value of any variable one by one in JavaScript, and similarly the (- -) symbol is used to decrease the value of any variable one by one. Who are called Increment and Decrement Operator respectively.

Types of Increment / Decrement Operator in JavaScript

To understand the table below, we will take the variable var a = 2

Examplenameresults
++ aPre-incrementThe value of a variable will first increase by 1. Then return the value of a.  
a ++Post-incrementwill first return the value of a variable. Then the value of a variable will increase by 1  
– -aPre-DecrementFirst the value of a variable will decrease by 1. Then return the value of a variable.  
a- –Post-decrementwill first return the value of a variable. Then the value of a variable decreases to 1.  

Let us understand Pre-increment from the following example.

Image

Explanation: Here we have the value of a variable 1. When we connect (++) in front of a variable. Then the value of a variable is first increased by 1 to 2, then 2 is printed.

Let us understand Post-increment from the following example.

Image

Explanation: Here the value of our $ b variable was 1. When we add (++) to the end of the $ a variable. Then the value of $ a variable will first print e. And we will get what has been increased by printing on the next line.

Let us understand Pre-Decrement from the following example.

Image

Explanation: Here we had the value of a variable 2. When we connect (- -) in front of a variable. Then the value of a variable is first reduced to 1, then 1 is printed.

Let us understand Post-decrement from the following example.

Image

Explanation: Here we had the value of b variable 2. When we add (- -) to the end of b variable. Then the value of the variable b will first print 2. And we will get what has been reduced by printing on the next line.

What are Logical Operators in JavaScript and how do Logical Operators work?

Image

Operators in JavaScript that make decisions based on two or more conditions.

All of the following Logical Operator supports JavaScript

OperatorName of the OperatorExampleResult  
&&Andx && yThe result will be true if both x and y are true.  
||Orx ||The y result will be true if any one of x and y is true.  
!Not! XThe result will be true if x is not true.  

What is Ternary Operator in JavaScript?

Image

According to the Oxford English Dictionary, the word Ternary means “made up of three parts”. As the name suggests, the Ternary Operator in JavaScript is a Conditional Operator consisting of three parts: Condition? Expression 1: Expression 2. If the condition is true, then Expression 1 will return otherwise Expression 2 will return. The Ternary Operator is a lot like the if el .else statement. Let’s look at the following example:

 

Image

What are Type Operators in JavaScript?

 

There are two Type Operators in JavaScript, the first being the instanceof operator, which is used to check if a particular variable is an instance of a class. Another is typeof Operator, which is used to check the type of a variable or value.

Example of instance of Operator:

Image

Example of type of Operator:

Image

What is the delete operator in JavaScript?

 

In JavaScript, the delete operator is used to delete a specific property of an object.

Example of delete Operator:

Image

What is JavaScript in Operator?

 

JavaScript uses the in Operator to find the specific property of an object or array.

Example of in Operator:

Image

Output

 

Image

Leave a Reply

Your email address will not be published. Required fields are marked *