SlideShare a Scribd company logo
2
Most read
4
Most read
5
Most read
11/30/2011
1
JavaScript
JavaScript is the scripting language of the
Web.
JavaScript is used in millions of Web pages
to add functionality, validate forms, detect
browsers, and much more.
11/30/2011 1Hassan Khan
What is JavaScript?
JavaScript was designed to add interactivity to HTML
pages
JavaScript is a scripting language
A scripting language is a lightweight programming
language
JavaScript is usually embedded directly into HTML
pages
JavaScript is an interpreted language (means that
scripts execute without preliminary compilation)
Everyone can use JavaScript without purchasing a
license
11/30/2011 2Hassan Khan
11/30/2011
2
Example
<html>
<body>
<script type="text/javascript">
document.write("This is my first JavaScript!");
</script>
</body>
</html>
11/30/2011 3Hassan Khan
How to Handle Simple
Browsers
Browsers that do not support JavaScript, will display
JavaScript as page content.
The HTML comment tag should be used to "hide" the
JavaScript.
Just add an HTML comment tag <!-- before the first
JavaScript statement, and a --> (end of comment) after
the last JavaScript statement.
11/30/2011 4Hassan Khan
11/30/2011
3
Example
The two forward slashes at the end of comment line (//) is
the JavaScript comment symbol. This prevents
JavaScript from executing the --> tag.
11/30/2011 5Hassan Khan
What can a JavaScript do?
JavaScript gives HTML designers a programming
tool
JavaScript can put dynamic text into an HTML page
JavaScript can react to events
JavaScript can read and write HTML elements
JavaScript can be used to validate data
JavaScript can be used to detect the visitor's
browser
JavaScript can be used to create cookies
11/30/2011 6Hassan Khan
11/30/2011
4
How To Use?
<script> tag is used to insert a JavaScript into
an HTML page.
Between <body> tag
Between <head> tag
11/30/2011 7Hassan Khan
How To Use (Cont.)?
JavaScripts in the body section will be
executed WHILE the page loads.
JavaScripts in the head section will be
executed when CALLED.
11/30/2011 8Hassan Khan
11/30/2011
5
JavaScript Statements
JavaScript is case sensitive.
Use of semicolon(;) in the end of statement is
optional.
document.write("Hello");
document.write("Hello")
11/30/2011 9Hassan Khan
JavaScript Comments
Single line comments start with //.
Multi line comments start with /* and end with
*/.
11/30/2011 10Hassan Khan
11/30/2011
6
JavaScript Variables
JavaScript variables are used to hold values
or expressions.
x=5, y=6, z=x+y
Rules for JavaScript variable names:
Variable names are case sensitive (y and Y
are two different variables)
Variable names must begin with a letter or
the underscore character
11/30/2011 11Hassan Khan
JavaScript Variables
Declaration
var x;
var carname;
Assign Values
x=5;
carname=“Toyota";
11/30/2011 12Hassan Khan
11/30/2011
7
JavaScript Arithmetic Operators
Y=5
11/30/2011 13Hassan Khan
JavaScript Assignment Operators
x = 5 and y=10
11/30/2011 14Hassan Khan
11/30/2011
8
+ Operator and Strings
To add two or more string variables together,
use the + operator.
11/30/2011 15Hassan Khan
Comparison Operators
11/30/2011 16Hassan Khan
11/30/2011
9
Logical Operators
11/30/2011 17Hassan Khan
If...Else Statements
used to perform different actions based on different
conditions.
if statement - use this statement to execute some
code only if a specified condition is true
if...else statement - use this statement to execute
some code if the condition is true and another code
if the condition is false
if...else if....else statement - use this statement to
select one of many blocks of code to be executed
switch statement - use this statement to select one
of many blocks of code to be executed
11/30/2011 18Hassan Khan
11/30/2011
10
Example (If)
11/30/2011 19Hassan Khan
Example (If...else)
11/30/2011 20Hassan Khan
11/30/2011
11
Example(If...else if...else)
11/30/2011 21Hassan Khan
Switch Statement
used to perform different actions based on
different conditions.
11/30/2011 22Hassan Khan
11/30/2011
12
Example (Switch)
11/30/2011 23Hassan Khan
Popup Boxes
Alert Box
alert(“Hello Every Body");
Confirm Box
confirm(“Press a button");
Prompt Box
prompt("Your name","")
11/30/2011 24
Hassan Khan
11/30/2011
13
Functions
A function will be executed by an event or by
a call to the function.
11/30/2011 25Hassan Khan
Example (Function)
11/30/2011 26Hassan Khan
11/30/2011
14
JavaScript Loops
You want the same block of code to run over and
over again in a row. Instead of adding several
almost equal lines in a script we can use loops to
perform a task like this.
In JavaScript, there are two different kind of loops:
for - loops through a block of code a specified
number of times
while - loops through a block of code while a
specified condition is true
11/30/2011 27Hassan Khan
The for Loop
11/30/2011 28Hassan Khan
11/30/2011
15
While Loop
11/30/2011 29Hassan Khan
The break Statement
The break statement will break the loop and
continue executing the code that follows after
the loop (if any).
11/30/2011 30Hassan Khan
11/30/2011
16
The continue Statement
The continue statement will break the current
loop and continue with the next value.
11/30/2011 31Hassan Khan
JavaScript Events
Events are actions that can be detected by
JavaScript.
Examples of events:
A mouse click
A web page or an image loading
Mousing over a hot spot on the web page
Selecting an input field in an HTML form
Submitting an HTML form
A keystroke
11/30/2011 32Hassan Khan
11/30/2011
17
Events
onLoad and onUnload
onFocus, onBlur and onChange
onSubmit
onMouseOver and onMouseOut
11/30/2011 33Hassan Khan
JavaScript Objects
JavaScript is an Object Oriented
Programming (OOP) language.
An OOP language allows you to define your
own objects and make your own variable
types.
We will start by looking at the built-in
JavaScript objects.
11/30/2011 34Hassan Khan
11/30/2011
18
JavaScript Objects and Properties
Properties are the values associated with an
object.
11/30/2011 35Hassan Khan
JavaScript String Object
The String object is used to manipulate a
stored piece of text.
Some String Methods
search()
toLowerCase()
toUpperCase()
11/30/2011 36Hassan Khan
11/30/2011
19
JavaScript Date Object
The Date object is used to work with dates
and times.
11/30/2011 37Hassan Khan
Data Comparison
?
11/30/2011 38Hassan Khan
11/30/2011
20
JavaScript Array Object
The Array object is used to store multiple
values in a single variable.
An array can be defined in three ways.
11/30/2011 39Hassan Khan
JavaScript Math Object
The Math object allows you to perform
mathematical tasks.
Math.PI
Math.E
Math.sqrt(number)
Math.round(4.7)
11/30/2011 40Hassan Khan
11/30/2011
21
JavaScript Navigator Object
The Navigator object allows you to
check/validate your Browser.
Navigator.appName,;
Navigator.appVersion
11/30/2011 41Hassan Khan

More Related Content

What's hot (9)

PPTX
Database systems - Chapter 2
shahab3
 
PPTX
E-R diagram in Database
Fatiha Qureshi
 
PPT
Lecture 16 17 code-generation
Iffat Anjum
 
PPTX
IPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriya
VijiPriya Jeyamani
 
PPT
Corba introduction and simple example
Alexia Wang
 
PDF
Json web token
Mayank Patel
 
PPT
Linq
Vishwa Mohan
 
PPT
Elementary cryptography
Prachi Gulihar
 
PPTX
Object oriented and function oriented design
Naveen Sagayaselvaraj
 
Database systems - Chapter 2
shahab3
 
E-R diagram in Database
Fatiha Qureshi
 
Lecture 16 17 code-generation
Iffat Anjum
 
IPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriya
VijiPriya Jeyamani
 
Corba introduction and simple example
Alexia Wang
 
Json web token
Mayank Patel
 
Elementary cryptography
Prachi Gulihar
 
Object oriented and function oriented design
Naveen Sagayaselvaraj
 

Viewers also liked (6)

PPTX
Ar3 c ati weco2 park actual work up to july 18 2014
kjstrong
 
PPTX
Filming powerpoint
afraidofthedark
 
PPTX
Ar3 c r&d plus demo weco2 park greenhouse
kjstrong
 
PPTX
CARACTERÍSTICAS INFORMÁTICA OO
Patricio Xtr
 
PPTX
Ar3 c ati weco2 park outdoor storage pad july 18 2014
kjstrong
 
PDF
Important marketing notes
ANNIEJAN
 
Ar3 c ati weco2 park actual work up to july 18 2014
kjstrong
 
Filming powerpoint
afraidofthedark
 
Ar3 c r&d plus demo weco2 park greenhouse
kjstrong
 
CARACTERÍSTICAS INFORMÁTICA OO
Patricio Xtr
 
Ar3 c ati weco2 park outdoor storage pad july 18 2014
kjstrong
 
Important marketing notes
ANNIEJAN
 
Ad

Similar to Java Script notes (20)

PDF
javascriptPresentation.pdf
wildcat9335
 
PPTX
Lecture 5 javascript
Mujtaba Haider
 
PPTX
Unit - 4 all script are here Javascript.pptx
kushwahanitesh592
 
PPTX
Unit III.pptx IT3401 web essentials presentatio
lakshitakumar291
 
PDF
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
pkaviya
 
PDF
Ch3- Java Script.pdf
HASENSEID
 
PDF
JAVA SCRIPT
Mohammed Hussein
 
PPTX
Cordova training : Day 3 - Introduction to Javascript
Binu Paul
 
PPTX
FFW Gabrovo PMG - JavaScript 1
Toni Kolev
 
PDF
internet Chapter 4-JavascripPrepare a ppt of video compression techniques bas...
wabii3179com
 
PPTX
JavaScript_III.pptx
rashmiisrani1
 
PPTX
Java script
Shyam Khant
 
PPTX
Web programming
Leo Mark Villar
 
PPTX
Introduction to Javascript
ambuj pathak
 
PPTX
Javascript
D V BHASKAR REDDY
 
PPTX
04-JS.pptx
RazanMazen4
 
PPTX
04-JS.pptx
RazanMazen4
 
PPTX
04-JS.pptx
RazanMazen4
 
PPT
UNIT 3.ppt
MadhurRajVerma1
 
PPTX
Java script
bosybosy
 
javascriptPresentation.pdf
wildcat9335
 
Lecture 5 javascript
Mujtaba Haider
 
Unit - 4 all script are here Javascript.pptx
kushwahanitesh592
 
Unit III.pptx IT3401 web essentials presentatio
lakshitakumar291
 
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
pkaviya
 
Ch3- Java Script.pdf
HASENSEID
 
JAVA SCRIPT
Mohammed Hussein
 
Cordova training : Day 3 - Introduction to Javascript
Binu Paul
 
FFW Gabrovo PMG - JavaScript 1
Toni Kolev
 
internet Chapter 4-JavascripPrepare a ppt of video compression techniques bas...
wabii3179com
 
JavaScript_III.pptx
rashmiisrani1
 
Java script
Shyam Khant
 
Web programming
Leo Mark Villar
 
Introduction to Javascript
ambuj pathak
 
Javascript
D V BHASKAR REDDY
 
04-JS.pptx
RazanMazen4
 
04-JS.pptx
RazanMazen4
 
04-JS.pptx
RazanMazen4
 
UNIT 3.ppt
MadhurRajVerma1
 
Java script
bosybosy
 
Ad

Recently uploaded (20)

PPT
21st Century Literature from the Philippines and the World QUARTER 1/ MODULE ...
isaacmendoza76
 
PPTX
week 1-2.pptx yueojerjdeiwmwjsweuwikwswiewjrwiwkw
rebznelz
 
PDF
Quiz Night Live May 2025 - Intra Pragya Online General Quiz
Pragya - UEM Kolkata Quiz Club
 
PDF
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
PDF
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
PDF
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
DOCX
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
PPTX
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
PPTX
Connecting Linear and Angular Quantities in Human Movement.pptx
AngeliqueTolentinoDe
 
PPTX
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
 
PPTX
Ward Management: Patient Care, Personnel, Equipment, and Environment.pptx
PRADEEP ABOTHU
 
PDF
Cooperative wireless communications 1st Edition Yan Zhang
jsphyftmkb123
 
PPTX
Practice Gardens and Polytechnic Education: Utilizing Nature in 1950s’ Hu...
Lajos Somogyvári
 
PPTX
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
PPTX
Matatag Curriculum English 8-Week 1 Day 1-5.pptx
KirbieJaneGasta1
 
PPTX
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
PPTX
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
PPTX
Natural Language processing using nltk.pptx
Ramakrishna Reddy Bijjam
 
PPTX
The Gift of the Magi by O Henry-A Story of True Love, Sacrifice, and Selfless...
Beena E S
 
21st Century Literature from the Philippines and the World QUARTER 1/ MODULE ...
isaacmendoza76
 
week 1-2.pptx yueojerjdeiwmwjsweuwikwswiewjrwiwkw
rebznelz
 
Quiz Night Live May 2025 - Intra Pragya Online General Quiz
Pragya - UEM Kolkata Quiz Club
 
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
Connecting Linear and Angular Quantities in Human Movement.pptx
AngeliqueTolentinoDe
 
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
 
Ward Management: Patient Care, Personnel, Equipment, and Environment.pptx
PRADEEP ABOTHU
 
Cooperative wireless communications 1st Edition Yan Zhang
jsphyftmkb123
 
Practice Gardens and Polytechnic Education: Utilizing Nature in 1950s’ Hu...
Lajos Somogyvári
 
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
Matatag Curriculum English 8-Week 1 Day 1-5.pptx
KirbieJaneGasta1
 
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
Natural Language processing using nltk.pptx
Ramakrishna Reddy Bijjam
 
The Gift of the Magi by O Henry-A Story of True Love, Sacrifice, and Selfless...
Beena E S
 

Java Script notes

  • 1. 11/30/2011 1 JavaScript JavaScript is the scripting language of the Web. JavaScript is used in millions of Web pages to add functionality, validate forms, detect browsers, and much more. 11/30/2011 1Hassan Khan What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight programming language JavaScript is usually embedded directly into HTML pages JavaScript is an interpreted language (means that scripts execute without preliminary compilation) Everyone can use JavaScript without purchasing a license 11/30/2011 2Hassan Khan
  • 2. 11/30/2011 2 Example <html> <body> <script type="text/javascript"> document.write("This is my first JavaScript!"); </script> </body> </html> 11/30/2011 3Hassan Khan How to Handle Simple Browsers Browsers that do not support JavaScript, will display JavaScript as page content. The HTML comment tag should be used to "hide" the JavaScript. Just add an HTML comment tag <!-- before the first JavaScript statement, and a --> (end of comment) after the last JavaScript statement. 11/30/2011 4Hassan Khan
  • 3. 11/30/2011 3 Example The two forward slashes at the end of comment line (//) is the JavaScript comment symbol. This prevents JavaScript from executing the --> tag. 11/30/2011 5Hassan Khan What can a JavaScript do? JavaScript gives HTML designers a programming tool JavaScript can put dynamic text into an HTML page JavaScript can react to events JavaScript can read and write HTML elements JavaScript can be used to validate data JavaScript can be used to detect the visitor's browser JavaScript can be used to create cookies 11/30/2011 6Hassan Khan
  • 4. 11/30/2011 4 How To Use? <script> tag is used to insert a JavaScript into an HTML page. Between <body> tag Between <head> tag 11/30/2011 7Hassan Khan How To Use (Cont.)? JavaScripts in the body section will be executed WHILE the page loads. JavaScripts in the head section will be executed when CALLED. 11/30/2011 8Hassan Khan
  • 5. 11/30/2011 5 JavaScript Statements JavaScript is case sensitive. Use of semicolon(;) in the end of statement is optional. document.write("Hello"); document.write("Hello") 11/30/2011 9Hassan Khan JavaScript Comments Single line comments start with //. Multi line comments start with /* and end with */. 11/30/2011 10Hassan Khan
  • 6. 11/30/2011 6 JavaScript Variables JavaScript variables are used to hold values or expressions. x=5, y=6, z=x+y Rules for JavaScript variable names: Variable names are case sensitive (y and Y are two different variables) Variable names must begin with a letter or the underscore character 11/30/2011 11Hassan Khan JavaScript Variables Declaration var x; var carname; Assign Values x=5; carname=“Toyota"; 11/30/2011 12Hassan Khan
  • 7. 11/30/2011 7 JavaScript Arithmetic Operators Y=5 11/30/2011 13Hassan Khan JavaScript Assignment Operators x = 5 and y=10 11/30/2011 14Hassan Khan
  • 8. 11/30/2011 8 + Operator and Strings To add two or more string variables together, use the + operator. 11/30/2011 15Hassan Khan Comparison Operators 11/30/2011 16Hassan Khan
  • 9. 11/30/2011 9 Logical Operators 11/30/2011 17Hassan Khan If...Else Statements used to perform different actions based on different conditions. if statement - use this statement to execute some code only if a specified condition is true if...else statement - use this statement to execute some code if the condition is true and another code if the condition is false if...else if....else statement - use this statement to select one of many blocks of code to be executed switch statement - use this statement to select one of many blocks of code to be executed 11/30/2011 18Hassan Khan
  • 10. 11/30/2011 10 Example (If) 11/30/2011 19Hassan Khan Example (If...else) 11/30/2011 20Hassan Khan
  • 11. 11/30/2011 11 Example(If...else if...else) 11/30/2011 21Hassan Khan Switch Statement used to perform different actions based on different conditions. 11/30/2011 22Hassan Khan
  • 12. 11/30/2011 12 Example (Switch) 11/30/2011 23Hassan Khan Popup Boxes Alert Box alert(“Hello Every Body"); Confirm Box confirm(“Press a button"); Prompt Box prompt("Your name","") 11/30/2011 24 Hassan Khan
  • 13. 11/30/2011 13 Functions A function will be executed by an event or by a call to the function. 11/30/2011 25Hassan Khan Example (Function) 11/30/2011 26Hassan Khan
  • 14. 11/30/2011 14 JavaScript Loops You want the same block of code to run over and over again in a row. Instead of adding several almost equal lines in a script we can use loops to perform a task like this. In JavaScript, there are two different kind of loops: for - loops through a block of code a specified number of times while - loops through a block of code while a specified condition is true 11/30/2011 27Hassan Khan The for Loop 11/30/2011 28Hassan Khan
  • 15. 11/30/2011 15 While Loop 11/30/2011 29Hassan Khan The break Statement The break statement will break the loop and continue executing the code that follows after the loop (if any). 11/30/2011 30Hassan Khan
  • 16. 11/30/2011 16 The continue Statement The continue statement will break the current loop and continue with the next value. 11/30/2011 31Hassan Khan JavaScript Events Events are actions that can be detected by JavaScript. Examples of events: A mouse click A web page or an image loading Mousing over a hot spot on the web page Selecting an input field in an HTML form Submitting an HTML form A keystroke 11/30/2011 32Hassan Khan
  • 17. 11/30/2011 17 Events onLoad and onUnload onFocus, onBlur and onChange onSubmit onMouseOver and onMouseOut 11/30/2011 33Hassan Khan JavaScript Objects JavaScript is an Object Oriented Programming (OOP) language. An OOP language allows you to define your own objects and make your own variable types. We will start by looking at the built-in JavaScript objects. 11/30/2011 34Hassan Khan
  • 18. 11/30/2011 18 JavaScript Objects and Properties Properties are the values associated with an object. 11/30/2011 35Hassan Khan JavaScript String Object The String object is used to manipulate a stored piece of text. Some String Methods search() toLowerCase() toUpperCase() 11/30/2011 36Hassan Khan
  • 19. 11/30/2011 19 JavaScript Date Object The Date object is used to work with dates and times. 11/30/2011 37Hassan Khan Data Comparison ? 11/30/2011 38Hassan Khan
  • 20. 11/30/2011 20 JavaScript Array Object The Array object is used to store multiple values in a single variable. An array can be defined in three ways. 11/30/2011 39Hassan Khan JavaScript Math Object The Math object allows you to perform mathematical tasks. Math.PI Math.E Math.sqrt(number) Math.round(4.7) 11/30/2011 40Hassan Khan
  • 21. 11/30/2011 21 JavaScript Navigator Object The Navigator object allows you to check/validate your Browser. Navigator.appName,; Navigator.appVersion 11/30/2011 41Hassan Khan