SlideShare a Scribd company logo
8
Most read
15
Most read
18
Most read
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
1
Operators in JavaScript
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
2
Contents
• Introduction to Operators
• Various Categories of Operators
• Usage of various Operators in Scripts
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
3
Operators
• An operator is used to transform one or more values into a
single resultant value.
• The value to which the operator is applied is referred as
operands.
• A combination of an operator and its operands is referred to
as an expression.
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
4
Arithmetic
Comparison
StringConditional
Assignment
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
5
Arithmetic Operators
• Arithmetic operators are the most familiar operators
because they are used every day to solve common math
calculations
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulous (Remainder after
division)
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
6
Arithmetic Operators
++ increment operator
_ _ decrement operator
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
7
<html>
<head> <title>Arithmetic Operators</title</head>
<body>
<script language="javascript">
a=20;b=3;
document.write("sum="+(a+b));
document.write("<br> remainder="+(a%b));
document.write("<br> increment="+(++a));
document.write("<br> decrement="+(--b)); </script>
</body>
</html>
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
8
Comparison Operators
• Comparision operators are used to compare two
values.
== Equal
!= Not equal
< = Less than or equal to
>= Greater than or equal to
==== Strictly equal
!== Strictly not equal
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
9
Continued..
• The equal(==) and not equal to (!=) operators
perform type casting for equality. For e.g. “5” ==
5 evaluate to true.
• The strictly equal(===) and strictly not equal to
(!==) operators perform type casting for equality.
For e.g. “5” === 5 evaluate
to false.
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
10
<html>
<head><title>Comparison Operator</title>
</head>
<body> <script language="javascript">
document.write("[5>6]->" + (5>6));
document.write("<br>[10<=15]->" + (10<=15));
document.write("<br>[4==6]->" + (4==6));
document.write("<br>[7!=8]->"+(7!=8));
</script>
</body>
</html>
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
11
String Operators
• String operators are those operators that are used to
perform operations on strings.
• Currently, JavaScript supports only the string
concatenation (+) operator.
• This operator is used to join two strings. For e.g.,
“pq” + “ab” produces “pqab”.
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
12
<html>
<head><title>String Operator</title>
</head>
<body>
<script language="javascript">
var c=3+5+"6";
var d=c;
document.write("hello"+"world");
document.write("<br>"+ 3 + "6");
document.write("<br>"+ 3 + 5 +"6");
document.write("<br>result =" +d);
</script> </body></html>
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
13
Assignment Operators
• The assignment operator is used to update the value
of a variable.
• Some assignment operators are combined with
other operators to perform a computation on the
value contained in a update the variable with the
new value.
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
14
Assignment Operators….
= sets the variable on the left of
the = operator to the value of
the expression on its right.
+= increments the variable on the
left of the += operator of the
expression on its right.
-= decrements the variable on the
left of the -= operator of the
expression on its right.
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
15
Assignment Operators….
*= multiplies the variable on the
left of the *= operator to the
value of the expression on its
right.
/= divides the variable on the
left of the /= operator of the
expression on its right.
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
16
<html>
<head><title>Assignment Operator
</title></head>
<body>
<script language="javascript"> a=3; b=6;
document.write("[a+=6]->"+(a+=6));
document.write("<br>[b*=5]->"+(b*=5)); </script>
</body>
</html>
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
17
Conditional Operators
• JavaScript supports the conditional expression
operator.
• They are ? And :
• The conditional expression operator is a ternary
operator since it takes three operands, a condition to
be evaluated and two alternative values to be
returned based on truth and falsity of a condition
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
18
Conditional Operators….
Syntax:
Condition ? Value1:value2
The condition expressed must return a value true or
false. If the condition is true, value 1 is the result of
the expression, otherwise value 2 is the result of the
expression
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
19
<html>
<head><title>Conditional Operator
</title></head>
<body>
<script language="javascript">
a=8;b=6;
c=a>b?a:b;
document.write(c+"is greater");
</script>
</body>
</html>
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
20
7/20/2015
Presented by:- Ms. Deepti Tara, Assoc. Prof.,
UIC, CU
21

More Related Content

ODP
Datatype in JavaScript
PDF
Fundamental JavaScript [UTC, March 2014]
PDF
Php Tutorials for Beginners
PPTX
Java script
PPTX
Javascript conditional statements
PPT
PHP variables
PDF
Introduction to Web Programming
PPTX
JavaScript Conditional Statements
Datatype in JavaScript
Fundamental JavaScript [UTC, March 2014]
Php Tutorials for Beginners
Java script
Javascript conditional statements
PHP variables
Introduction to Web Programming
JavaScript Conditional Statements

What's hot (20)

PPSX
Javascript variables and datatypes
PPT
Introduction to Javascript
PDF
JavaScript - Chapter 12 - Document Object Model
PDF
JavaScript - Chapter 3 - Introduction
PDF
jQuery for beginners
PPTX
jQuery
PPTX
Introduction to php
PPTX
Javascript
PPTX
Event In JavaScript
PPT
JavaScript & Dom Manipulation
PPTX
Lab #2: Introduction to Javascript
PDF
Javascript basics
PDF
Basics of JavaScript
PDF
Class and Objects in Java
PPTX
Java script
PDF
Javascript essentials
PDF
JavaScript - Chapter 7 - Advanced Functions
PDF
JavaScript - Chapter 8 - Objects
PPT
SQLITE Android
PPTX
Angular Data Binding
Javascript variables and datatypes
Introduction to Javascript
JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 3 - Introduction
jQuery for beginners
jQuery
Introduction to php
Javascript
Event In JavaScript
JavaScript & Dom Manipulation
Lab #2: Introduction to Javascript
Javascript basics
Basics of JavaScript
Class and Objects in Java
Java script
Javascript essentials
JavaScript - Chapter 7 - Advanced Functions
JavaScript - Chapter 8 - Objects
SQLITE Android
Angular Data Binding
Ad

Similar to Javascript operators (20)

PPTX
Operator 04 (js)
PPTX
Opeartor &amp; expression
PPT
JavaScript Operators
PPTX
Java script session 4
KEY
JavaScript: Operators and Expressions
PPTX
Logical Operators C/C++ language Programming
PPTX
Operators used in vb.net
PPTX
Python operators part2
PPTX
datatypes-and-operators in wed development.pptx
PDF
PDF
C sharp chap3
PDF
JavaScript operators
PDF
JavaScript - Chapter 5 - Operators
PPTX
Oop using JAVA
ODP
Operators
PPTX
11operator in c#
PPTX
Operators in java
PPTX
Introduction to JavaScript Scripting Language
PPTX
Operator 04 (js)
Opeartor &amp; expression
JavaScript Operators
Java script session 4
JavaScript: Operators and Expressions
Logical Operators C/C++ language Programming
Operators used in vb.net
Python operators part2
datatypes-and-operators in wed development.pptx
C sharp chap3
JavaScript operators
JavaScript - Chapter 5 - Operators
Oop using JAVA
Operators
11operator in c#
Operators in java
Introduction to JavaScript Scripting Language
Ad

Recently uploaded (20)

PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
PPT on Performance Review to get promotions
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
composite construction of structures.pdf
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
DOCX
573137875-Attendance-Management-System-original
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPT on Performance Review to get promotions
Foundation to blockchain - A guide to Blockchain Tech
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Lesson 3_Tessellation.pptx finite Mathematics
composite construction of structures.pdf
Embodied AI: Ushering in the Next Era of Intelligent Systems
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Lecture Notes Electrical Wiring System Components
Strings in CPP - Strings in C++ are sequences of characters used to store and...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Internet of Things (IOT) - A guide to understanding
CYBER-CRIMES AND SECURITY A guide to understanding
573137875-Attendance-Management-System-original
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx

Javascript operators

  • 1. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 1 Operators in JavaScript
  • 2. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 2 Contents • Introduction to Operators • Various Categories of Operators • Usage of various Operators in Scripts
  • 3. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 3 Operators • An operator is used to transform one or more values into a single resultant value. • The value to which the operator is applied is referred as operands. • A combination of an operator and its operands is referred to as an expression.
  • 4. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 4 Arithmetic Comparison StringConditional Assignment
  • 5. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 5 Arithmetic Operators • Arithmetic operators are the most familiar operators because they are used every day to solve common math calculations + Addition - Subtraction * Multiplication / Division % Modulous (Remainder after division)
  • 6. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 6 Arithmetic Operators ++ increment operator _ _ decrement operator
  • 7. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 7 <html> <head> <title>Arithmetic Operators</title</head> <body> <script language="javascript"> a=20;b=3; document.write("sum="+(a+b)); document.write("<br> remainder="+(a%b)); document.write("<br> increment="+(++a)); document.write("<br> decrement="+(--b)); </script> </body> </html>
  • 8. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 8 Comparison Operators • Comparision operators are used to compare two values. == Equal != Not equal < = Less than or equal to >= Greater than or equal to ==== Strictly equal !== Strictly not equal
  • 9. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 9 Continued.. • The equal(==) and not equal to (!=) operators perform type casting for equality. For e.g. “5” == 5 evaluate to true. • The strictly equal(===) and strictly not equal to (!==) operators perform type casting for equality. For e.g. “5” === 5 evaluate to false.
  • 10. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 10 <html> <head><title>Comparison Operator</title> </head> <body> <script language="javascript"> document.write("[5>6]->" + (5>6)); document.write("<br>[10<=15]->" + (10<=15)); document.write("<br>[4==6]->" + (4==6)); document.write("<br>[7!=8]->"+(7!=8)); </script> </body> </html>
  • 11. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 11 String Operators • String operators are those operators that are used to perform operations on strings. • Currently, JavaScript supports only the string concatenation (+) operator. • This operator is used to join two strings. For e.g., “pq” + “ab” produces “pqab”.
  • 12. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 12 <html> <head><title>String Operator</title> </head> <body> <script language="javascript"> var c=3+5+"6"; var d=c; document.write("hello"+"world"); document.write("<br>"+ 3 + "6"); document.write("<br>"+ 3 + 5 +"6"); document.write("<br>result =" +d); </script> </body></html>
  • 13. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 13 Assignment Operators • The assignment operator is used to update the value of a variable. • Some assignment operators are combined with other operators to perform a computation on the value contained in a update the variable with the new value.
  • 14. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 14 Assignment Operators…. = sets the variable on the left of the = operator to the value of the expression on its right. += increments the variable on the left of the += operator of the expression on its right. -= decrements the variable on the left of the -= operator of the expression on its right.
  • 15. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 15 Assignment Operators…. *= multiplies the variable on the left of the *= operator to the value of the expression on its right. /= divides the variable on the left of the /= operator of the expression on its right.
  • 16. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 16 <html> <head><title>Assignment Operator </title></head> <body> <script language="javascript"> a=3; b=6; document.write("[a+=6]->"+(a+=6)); document.write("<br>[b*=5]->"+(b*=5)); </script> </body> </html>
  • 17. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 17 Conditional Operators • JavaScript supports the conditional expression operator. • They are ? And : • The conditional expression operator is a ternary operator since it takes three operands, a condition to be evaluated and two alternative values to be returned based on truth and falsity of a condition
  • 18. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 18 Conditional Operators…. Syntax: Condition ? Value1:value2 The condition expressed must return a value true or false. If the condition is true, value 1 is the result of the expression, otherwise value 2 is the result of the expression
  • 19. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 19 <html> <head><title>Conditional Operator </title></head> <body> <script language="javascript"> a=8;b=6; c=a>b?a:b; document.write(c+"is greater"); </script> </body> </html>
  • 20. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 20
  • 21. 7/20/2015 Presented by:- Ms. Deepti Tara, Assoc. Prof., UIC, CU 21