JS Operators

      No Comments on JS Operators

JS Arithmetic Operators

OperatorDescription
+Addition
Subtraction
*Multiplication
/Division
%Modulus
++Increment
Decrement

JS Assignment Operators

OperatorExampleSame As
=x = yx = y
+=x += yx = x + y
-=x -= yx = x – y
*=x *= yx = x * y
/=x /= yx = x / y
%=x %= yx = x % y

JS Comparison Operators

OperatorDescription
==equal to
===equal value and equal type
!=not equal
!==not equal value or not equal type
>greater than
<less than
>=greater than or equal to
<=less than or equal to
?ternary operator

JS Logical Operators

OperatorDescription
&&logical and
||logical or
!logical not

JS Bitwise Operators

OperatorDescriptionExampleSame asResultDecimal
&ANDx = 5 & 10101 & 00010001 1
|ORx = 5 | 10101 | 00010101 5
~NOTx = ~ 5 ~01011010 10
^XORx = 5 ^ 10101 ^ 00010100 4
<<Zero fill left shiftx = 5 << 10101 << 11010 10
>>Signed right shiftx = 5 >> 10101 >> 10010  2
>>>Zero fill right shiftx = 5 >>> 10101 >>> 10010  2

JS Type Operators

OperatorDescription
typeofReturns the type of a variable
instanceofReturns true if an object is an instance of an object type
Usage

Assignment operator (=)

The assignment operator (=) assigns a value to a variable.

var x = 15;         // assign the value 15 to x
var y = 20;         // assign the value 20 to y
var z = x + y;     // assign the value 35 to z (x + y) 

Addition operator (+)

Addition operator (+) adds variables, similar to mathematical multiplication.

var x=2;
var a=5;
var d=x+a;

Multiplication operator (*)

The multiplication operator (*) multiplies numbers, similar to multiplication we perform.

var x = 5;
var y = 2;
var z = x * y; 

Leave a Reply

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