Loading Please Wait...

Logo Lynxsia IT Solutions

JavaScript Operators

JS Operators

JavaScript Operators are used to perform operations and calculations on numbers, string, variables, etc.

Types of Operators

JavaScript has following types of operators:

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • Logical Operators
  • Bitwise Operators
  • Ternary Operators
  • Type Operators
Operators and Operands

The numbers or variables used in operations are called operands.

The operation to be performed between numbers or variables is defined by an operator.

Example Operands Operator
5 + 6 5 , 6 +
a - b a , b -
a * 6 a , 6 *
Arithmetic Operators

Arithmetic Operators are used to perform arithmetic operatiorns:

Operators Description Example
+ Addition a + b
- Subtraction a - b
* Multiplication a * b
** Exponentiation a ** b
/ Division a / b
% Modulus (Remainder) a % b
++ Increment a++
-- Decrement --a
Assignment Operators

Assignment Operators assign values to JavaScript variables.

Operators Example Same As
= a = b a = b
+= a += b a = a + b
-= a -= b a = a - b
*= a *= b a = a * b
/= a /= b a = a / b
%= a %= b a = a % b
Comparison Operators

Comparison Operators are used to compare variables and values.

Operators Description Example
== equal to (value) a == b
=== equal value and equal type a === b
!= not equal (value) a != b
!== not equal value or not equal type a !== b
> greater than a > b
< less than a < b
>= greater than or equal to a >= b
<= less than or equal to a <= b
Logical Operators

Logical Operators are used to determine the logic between variables or values.

Operators Description Example
&& logical AND a && b
|| logical OR a || b
! logical NOT (Negation) !a
Bitwise Operators

Any numeric operand in the operation is converted into a 32 bit number. The result is converted back to a JavaScript number.

Operators Description Example
& AND a & b
| OR a | b
~ NOT (Negation) ~a
^ XOR a ^ b
<< left shift a << b
>> right shift a >> b
>>> unsigned right shift a >>> b
Type Operators
Operators Description Example
typeof Returns the type of a variable typeof a
instanceof Returns true if an object is an instance of an object type instanceofa
Ternary Operators

JavaScript also contains a conditional (ternary) operator that assigns a value to a variable based on some condition.

Syntax

variablename = (condition) ? value1:value2

Example

					 
        
          let voteable = (age < 18) ? "Too young" : "Old enough";
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved