0% found this document useful (0 votes)
18 views

JavaScript Operators

JavaScript supports various types of operators including arithmetic, comparison, logical, and assignment operators. Arithmetic operators perform math operations like addition and subtraction. Comparison operators compare values and return true or false. Logical operators combine conditional statements. Assignment operators assign values to variables.

Uploaded by

goswamishreshth4
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

JavaScript Operators

JavaScript supports various types of operators including arithmetic, comparison, logical, and assignment operators. Arithmetic operators perform math operations like addition and subtraction. Comparison operators compare values and return true or false. Logical operators combine conditional statements. Assignment operators assign values to variables.

Uploaded by

goswamishreshth4
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

JavaScript Operators

What is an operator?
Operators are used to assign values, compare values, perform arithmetic operations, and more.

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 Operators
 Logical or Relational Operators
 Assignment Operators

Arithmetic Operators:
In JavaScript, arithmetic operators are symbols or functions that allow you to perform basic
mathematical operations on numeric values.

1 + Addition

Adds two operands

Ex: A + B will give 30

2 – Subtraction

Subtracts the second operand from the first

Ex: A - B will give -10

3 * Multiplication

Multiply both operands

Ex: A * B will give 200

4. / Division

Divide the numerator by the denominator

Ex: B / A will give 2

5 % Modulus

Outputs the remainder of an integer division

Ex: B % A will give 0


6. ++ Increment

Increases an integer value by one

Ex: A++ will give 11

7 -- Decrement

Decreases an integer value by one

Ex: A-- will give 9

Note − Addition operator + works for Numeric as well as Strings. e.g. "a" + 10
will give "a10".

Comparison Operators:
Comparison operators in JavaScript are used to compare values and determine the relationship
between them. They return a Boolean value (true or false) based on whether the comparison is true
or false.

Assume variable A holds 12 and variable B holds 20, then –

1 = = 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.

2 != 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.

3 > 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.


4 < Lessthan

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.

5 >= GreaterthanorEqualto

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.

6 <= LessthanorEqualto

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:
1 && LogicalAND

If both the operands are true, then the condition becomes true.

Ex: A && B is true.

True, true = true

True , false = false

False, true = false

False , false = false

2 || LogicalOR

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

Ex: A | | B is true.

True , true = true

False , true = true

True , false = true

False , false
3 ! LogicalNOT

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:
1 = SimpleAssignment

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

2 += AddandAssignment

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

3 −= SubtractandAssignment

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

4 *= MultiplyandAssignment

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

5 /= DivideandAssignment

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

6 %= ModulesandAssignment

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