SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

Computer architecture pipelining
Computer architecture pipeliningComputer architecture pipelining
Computer architecture pipeliningMazin Alwaaly
 
Binary Arithmetic Presentation about Binary Numbers 2015
Binary Arithmetic Presentation about Binary Numbers 2015Binary Arithmetic Presentation about Binary Numbers 2015
Binary Arithmetic Presentation about Binary Numbers 2015An Ariyan
 
Arsitektur komputer pertemuan 11
Arsitektur komputer pertemuan 11Arsitektur komputer pertemuan 11
Arsitektur komputer pertemuan 11Afrina Ramadhani
 
Other software processes (Software project Management)
Other software processes (Software project Management)Other software processes (Software project Management)
Other software processes (Software project Management)Ankit Gupta
 
Direct memory access
Direct memory accessDirect memory access
Direct memory accessshubham kuwar
 
Logic microoperations
Logic microoperationsLogic microoperations
Logic microoperationsNitesh Singh
 
Basic Computer Organization and Design
Basic Computer Organization and DesignBasic Computer Organization and Design
Basic Computer Organization and Designmekind
 
Addressing modes
Addressing modesAddressing modes
Addressing modesAsif Iqbal
 
Logical, Shift, and Rotate Instruction
Logical, Shift, and Rotate InstructionLogical, Shift, and Rotate Instruction
Logical, Shift, and Rotate InstructionBadrul Alam
 
Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.NA000000
 
Floating point representation
Floating point representationFloating point representation
Floating point representationmissstevenson01
 
8086 memory segmentation
8086 memory segmentation8086 memory segmentation
8086 memory segmentationSridari Iyer
 

Mais procurados (20)

Computer architecture pipelining
Computer architecture pipeliningComputer architecture pipelining
Computer architecture pipelining
 
Binary Arithmetic Presentation about Binary Numbers 2015
Binary Arithmetic Presentation about Binary Numbers 2015Binary Arithmetic Presentation about Binary Numbers 2015
Binary Arithmetic Presentation about Binary Numbers 2015
 
Lecture 2 process
Lecture 2   processLecture 2   process
Lecture 2 process
 
Arsitektur komputer pertemuan 11
Arsitektur komputer pertemuan 11Arsitektur komputer pertemuan 11
Arsitektur komputer pertemuan 11
 
Other software processes (Software project Management)
Other software processes (Software project Management)Other software processes (Software project Management)
Other software processes (Software project Management)
 
Direct memory access
Direct memory accessDirect memory access
Direct memory access
 
Logic microoperations
Logic microoperationsLogic microoperations
Logic microoperations
 
Basic Computer Organization and Design
Basic Computer Organization and DesignBasic Computer Organization and Design
Basic Computer Organization and Design
 
File access method
File access methodFile access method
File access method
 
process control block
process control blockprocess control block
process control block
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
Ch3
Ch3Ch3
Ch3
 
Logical, Shift, and Rotate Instruction
Logical, Shift, and Rotate InstructionLogical, Shift, and Rotate Instruction
Logical, Shift, and Rotate Instruction
 
Micro program example
Micro program exampleMicro program example
Micro program example
 
Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.
 
Floating point representation
Floating point representationFloating point representation
Floating point representation
 
Modes of transfer
Modes of transferModes of transfer
Modes of transfer
 
DMA operation
DMA operationDMA operation
DMA operation
 
8086 memory segmentation
8086 memory segmentation8086 memory segmentation
8086 memory segmentation
 
Input output
Input outputInput output
Input output
 

Destaque

Ar3 c ati weco2 park actual work up to july 18 2014
Ar3 c ati weco2 park actual work up to july 18 2014Ar3 c ati weco2 park actual work up to july 18 2014
Ar3 c ati weco2 park actual work up to july 18 2014kjstrong
 
Ar3 c r&d plus demo weco2 park greenhouse
Ar3 c r&d plus demo weco2 park greenhouseAr3 c r&d plus demo weco2 park greenhouse
Ar3 c r&d plus demo weco2 park greenhousekjstrong
 
CARACTERÍSTICAS INFORMÁTICA OO
CARACTERÍSTICAS INFORMÁTICA OOCARACTERÍSTICAS INFORMÁTICA OO
CARACTERÍSTICAS INFORMÁTICA OOPatricio Xtr
 
Ar3 c ati weco2 park outdoor storage pad july 18 2014
Ar3 c ati weco2 park outdoor storage pad july 18 2014Ar3 c ati weco2 park outdoor storage pad july 18 2014
Ar3 c ati weco2 park outdoor storage pad july 18 2014kjstrong
 
Important marketing notes
Important marketing notesImportant marketing notes
Important marketing notesANNIEJAN
 

Destaque (6)

Ar3 c ati weco2 park actual work up to july 18 2014
Ar3 c ati weco2 park actual work up to july 18 2014Ar3 c ati weco2 park actual work up to july 18 2014
Ar3 c ati weco2 park actual work up to july 18 2014
 
Filming powerpoint
Filming powerpointFilming powerpoint
Filming powerpoint
 
Ar3 c r&d plus demo weco2 park greenhouse
Ar3 c r&d plus demo weco2 park greenhouseAr3 c r&d plus demo weco2 park greenhouse
Ar3 c r&d plus demo weco2 park greenhouse
 
CARACTERÍSTICAS INFORMÁTICA OO
CARACTERÍSTICAS INFORMÁTICA OOCARACTERÍSTICAS INFORMÁTICA OO
CARACTERÍSTICAS INFORMÁTICA OO
 
Ar3 c ati weco2 park outdoor storage pad july 18 2014
Ar3 c ati weco2 park outdoor storage pad july 18 2014Ar3 c ati weco2 park outdoor storage pad july 18 2014
Ar3 c ati weco2 park outdoor storage pad july 18 2014
 
Important marketing notes
Important marketing notesImportant marketing notes
Important marketing notes
 

Semelhante a JavaScript Fundamentals Explained

Semelhante a JavaScript Fundamentals Explained (20)

Java script
Java scriptJava script
Java script
 
Basics of Javascript
Basics of Javascript Basics of Javascript
Basics of Javascript
 
Web designing unit 4
Web designing unit 4Web designing unit 4
Web designing unit 4
 
Cordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptCordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to Javascript
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Javascript tutorial basic for starter
Javascript tutorial basic for starterJavascript tutorial basic for starter
Javascript tutorial basic for starter
 
Unit 2.5
Unit 2.5Unit 2.5
Unit 2.5
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
 
Unit 2.5
Unit 2.5Unit 2.5
Unit 2.5
 
Javascript tutorial
Javascript tutorialJavascript tutorial
Javascript tutorial
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
JavaScript Lecture notes.pptx
JavaScript Lecture notes.pptxJavaScript Lecture notes.pptx
JavaScript Lecture notes.pptx
 
Web programming
Web programmingWeb programming
Web programming
 
Javascript
JavascriptJavascript
Javascript
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Java script
Java scriptJava script
Java script
 
Cutting the Fat
Cutting the FatCutting the Fat
Cutting the Fat
 

Último

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Último (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

JavaScript Fundamentals Explained

  • 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