JavaScript operators

Relational Operators

JavaScript operators are used to perform to the operations like arithmetic, assign the values, comparison values and check the condition s and more…

Per suppose “var   c = a +   b “; var is a key word and a, b, c are operands then =, + are operators.

We have number of operators like below

Javascript Arithmetic Operators:-

Arithmetic operators are used to perform all arithmetic operations like addition, subtractions, multiplication, division, modulus ….etc

These operators are [+,-,*,/,%].

JavaScript supports the following arithmetic operators – we are going to assign variable x, y.  x  have 10 and variable y have 20, then

S.NO Operator & Description
1 + Addition

Adds two operands Ex: x + y will give 30

2 – Subtraction Subtracts the second operand from the first Ex: x – y will give -10
3 * Multiplication Multiply both operands

Ex: x * y will give 200

4 / Division Divide the values  and quotient will take

Ex: y/ x will give 2

5 % Modulus Outputs the remainder will take here

Ex: y % x will give 0

Javascript Relational Operators:-

The relational operators are going to comparison any using this operators like <, >, <=, >=,! =

JavaScript following comparison operators – per example variable X have 10 and variable Y have 20, then

S.NO Operator & Description
1 > Greater than

Compare  two operands Ex: x > y will give “not true”

2 < Less than

Compare  two operands Ex: x < y will give “true”

3 >= GreaterthanorEqualto

Compare  two operands Ex: x >= y will give “ not true”

4 <=LessrthanorEqualto

Compare  two operands Ex: x <= y will give “ true”

5 != NotEqualto

Compare  two operands Ex: x != y will give “true”

Javascript Logical Operators:-

The Logical operators are going to perform logical operations like &&, || , !

JavaScript following logical operations – per example variable X have 10 and variable Y have 20, then

S.NO Operator & Description
1 && LogicalAND

If both the operands are non-zero, then the condition becomes  true

EX:- x&&y is “ true ”

2 || LogicalOR

If any of the two operands are non-zero, then the condition becomes  true

EX:- x||y is “ true ”

3 ! LogicalNOT

It reverse the logical state of it’s operands in this case the login is true then it will false the statement

EX:- !x&&y is “ false ”

Javascript Arithmetic Assignment Operators:-

JavaScript following arithmetic assignment  operations like

+=, -+, *=, /=, %=

 

S.NO Operator & Description
1 += AddandAssignment

It will going to add the right operand to the left operand

Ex: x += y is equivalent to y = x+y

2 −= SubtractandAssignment

It will going to subtract  the right operand to the left operand

Ex: x -= y is equivalent to y = x-y

3 *= MultiplyandAssignment

It will going to multiple  the right operand to the left operand

Ex: x *= y is equivalent to y = x*y

4 /= DivideandAssignment

It will going to divides the right operand to the left operand

Ex: x /= y is equivalent to y = x/y

5 %= ModulesandAssignment It will going to modulus the right operand to the left operand

Ex: x %= y is equivalent to y = x%y

Javascript Assignment Operators:-

JavaScript following assignment operations like

=, ==, ===

S.NO Operator & Description
1 =  Assignment

It will Assigns the  values from the right side operand to the left side

EX:- x=10;

2 = =  Equal

It will check  the  two operands are equal or not, so if that operands are equal  than condition is true

EX:- x=10;y=20;

X==y is not true

3 === Equal

It will check the two operands are equal the value and equal the type ,then only it will becomes true

EX:- x=10; y=”10”;

X==y is not true

Javascript Conditional Operators:-

JavaScript following Conditional operations like (? : )

? :  Conditional

It will check If Condition is true? Then value X : Otherwise value Y

Javascript Boolean Operators:-

JavaScript following Boolean  operations like true and false,

Very often, in scripting , you will need a data type values can only have one of two values, like true or false,Yes or No, On or off.

Javascript Increment & Decrement Operators:-

JavaScript following Increment & Decrement   operations like ++,–

X=10;

++ Increment Increases an integer value by one

Ex: x++ will give 11

— Decrement Decreases an integer value by one

Ex: x– will give 9

Javascript Bitwise Operators or Javascript Ternary Operators:-

JavaScript following bitwise or ternary operators like

& BitwiseAND, | BitWiseOR, ^ BitwiseXOR, ~ BitwiseNot, << LeftShift, >> RightShift

Per example variable value X have 2 and variable value Y have 3, then

S.NO Operator & Description
1 & BitwiseAND

It will check  a Boolean AND operation on each bit of its integer arguments. Ex: x & y is 2

2 | BitWiseOR

It will check  a Boolean OR operation on each bit of its integer arguments. Ex: x | y is 3.

3 ^ BitwiseXOR

It will check  a Boolean performed OR operation on each bit of its integer arguments. performed OR means that either operand one is true or operand two is true, but not both.

Ex: x y is 1.

4 ~ BitwiseNot

It will check a unary operator and operates by reversing all the bits in the operand.

Ex: y is -4.

5 << LeftShift

It will check to moves all the bits value in its first operand to the left by the number of places specified in the second value operand.  it returns 1 if the bits are different.

Ex: x << 1 is 4.

6 >> RightShift

It will check  Binary Right Shift Operator. The left operand’s value is moved right by the number of bits specified by the right operand

Ex: x s>> 1 is 1.

 

Leave a Reply

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