0% found this document useful (0 votes)
13 views10 pages

Javascript Operators

Uploaded by

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

Javascript Operators

Uploaded by

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

JavaScript Operators

JavaScript operators are symbols that are used to


perform operations on operands.
There are following types of operators in JavaScript.
1. Arithmetic Operators
2. Comparison (Relational) Operators
3. Logical Operators
4. Assignment Operators
JavaScript Arithmetic Operators
Arithmetic operators are used to perform arithmetic operations
on the operands. The following operators are known as JavaScript
arithmetic operators.
Operator Description Example
+ Addition 10+20 = 30
- Subtraction 20-10 = 10
* Multiplication 10*20 = 200
/ Division 20/10 = 2
% Modulus (Remainder) 20%10 = 0
++ Increment var a=10; a++; Now a = 11
-- Decrement var a=10; a--; Now a = 9
** Exponentiation- raises the var x = 5;
1st operand to the power of var z = x ** 2; // result is
2nd the operand 25
Example of Arithmetic Operators
<!DOCTYPE html>
<html>
<head>
<title>Arithmetic Operators</title>
</head>
<body>
<script>
var a,b;
a = 10;
b = 5;
document.write("\n Arithmetic Operation");
document.write("<br>");
document.write("Addition of two Numbers:", a+b);
document.write("<br>");
document.write("Subtraction of two numbers:", a-b);
document.write("<br>");
document.write("Division of two Numbers:", a/b);
document.write("<br>");
document.write("Multiplication of two Numbers:", a*b);
document.write("<br>");
</script>
</body>
</html>
OUTPUT:
Arithmetic Operation
Addition of two Numbers:15
Subtaction of two numbers:5
Division of two Numbers:2
Multiplication of two Numbers:50

Practical Question
1. Write a JavaScript program to calculate multiplication
and division of two numbers (input from user).
OUTPUT:
JavaScript Comparison Operators
The JavaScript comparison operator compares the two
operands. The comparison operators are as follows:
Operator Description Example
== Is equal to (Value checking) 10==20 = false
a (char) == a (varchar) -> True
=== Identical (Value checking, equal 10==20 = false
and of same type)
10 (int) == 10 (float) -> False
10 (int) == 10 (int) -> True

!= Not equal to 10!=20 = true

!== Not Identical 20!==20 = false

> Greater than 20>10 = true

>= Greater than or equal to 20>=10 = true


JavaScript Logical Operators
The following operators are known as JavaScript
logical operators.

Operator Description Example


&& Logical AND (10==20 && 20==33) = false

|| Logical OR (10==20 || 20==33) = false

! Logical Not !(10==20) = true


JavaScript Assignment Operators
The following operators are known as JavaScript
assignment operators.
Operator Description Example
= Assign a= 20;
+= Add and assign var a=10;
a+=20; Result: a = 30
-= Subtract and assign var a=20;
a-=10; Result: a = 10
*= Multiply and assign var a=2;
a*=2; Result: a = 4
/= Divide and assign var a=10;
a/=2; Result: a = 5
%= Modulus and assign var a=10;
a%=2; Result: a = 0

You might also like