0% found this document useful (0 votes)
21 views3 pages

Module 5 - Conditionals and Loops

notes - conditionals and loops operators

Uploaded by

Sangeetha Mani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

Module 5 - Conditionals and Loops

notes - conditionals and loops operators

Uploaded by

Sangeetha Mani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Module 5-Conditionals and Loops

What is an Operator?
Let us take a simple expression: 4 + 5 is equal to 9. Here 4 and 5 are called operands and ‘+’
is called the operator. JavaScript supports the following types of operators.
 Arithmetic Operators
 Comparison(Relational) Operators
 Logical Operators
 Assignment Operators

Arithmetic Operators
Assume variable A holds 10 and variable B holds 20, then

Operator & Description

+ (Addition)
Adds two operands
Ex: A + B will give 30

- (Subtraction)
Subtracts the second operand from the first
Ex: A - B will give -10

* (Multiplication)
Multiply both operands
Ex: A * B will give 200

/ (Division)
Divide the numerator by the denominator
Ex: B / A will give 2

% (Modulus)
Outputs the remainder of an integer division
Ex: B % A will give 0

++ (Increment)
Increases an integer value by one
Ex: A++ will give 11

-- (Decrement)
Decreases an integer value by one
Ex: A-- will give 9

Comparison or Relational Operators


Comparison operators return true or false values
JavaScript supports the following comparison operators −
Assume variable A holds 10 and variable B holds 20, then −

Operator & Description

= = (Equal)
Checks if the value of two operands are equal or not, if yes, then the condition becomes
true.
Ex: (A == B) is not true.

!= (Not Equal)
Checks if the value of two operands are equal or not, if the values are not equal, then the
condition becomes true.
Ex: (A != B) is true.

> (Greater than)


Checks if the value of the left operand is greater than the value of the right operand, if yes,
then the condition becomes true.
Ex: (A > B) is not true.

< (Less than)


Checks if the value of the left operand is less than the value of the right operand, if yes,
then the condition becomes true.
Ex: (A < B) is true.

>= (Greater than or Equal to)


Checks if the value of the left operand is greater than or equal to the value of the right
operand, if yes, then the condition becomes true.
Ex: (A >= B) is not true.

<= (Less than or Equal to)


Checks if the value of the left operand is less than or equal to the value of the right
operand, if yes, then the condition becomes true.
Ex: (A <= B) is true.

Logical Operators
JavaScript supports the following logical operators −
Assume variable A holds 10 and variable B holds 20, then −

Operator & Description

&& (Logical AND)


If both the operands are non-zero, then the condition becomes true.
Ex: (A && B) is true.
|| (Logical OR)
If any of the two operands are non-zero, then the condition becomes true.
Ex: (A || B) is true.

! (Logical NOT)
Reverses the logical state of its operand. If a condition is true, then the Logical NOT
operator will make it false.
Ex: ! (A && B) is false.

Assignment Operators
JavaScript supports the following assignment operators −

Operator & Description

= (Simple Assignment )
Assigns values from the right side operand to the left side operand
Ex: C = A + B will assign the value of A + B into C

+= (Add and Assignment)


It adds the right operand to the left operand and assigns the result to the left operand.
Ex: C += A is equivalent to C = C + A

−= (Subtract and Assignment)


It subtracts the right operand from the left operand and assigns the result to the left
operand.
Ex: C -= A is equivalent to C = C - A

*= (Multiply and Assignment)


It multiplies the right operand with the left operand and assigns the result to the left
operand.
Ex: C *= A is equivalent to C = C * A

/= (Divide and Assignment)


It divides the left operand with the right operand and assigns the result to the left operand.
Ex: C /= A is equivalent to C = C / A

%= (Modules and Assignment)


It takes modulus using two operands and assigns the result to the left operand.
Ex: C %= A is equivalent to C = C % A

You might also like