SlideShare a Scribd company logo
1 of 15
Basic JavaScript
What is JS?
 JavaScript is the programming language of HTML
and the Web.
Introduction
 Its Free and (NO) need engine
 Simple and Easy to learn
 Lightweight and Fast to code
 Front & Back side coverage
 Third party library
 Growth community and docs
JS General format
<html>
<head>
<title>Hello World in JavaScript</title>
</head>
<body>
<script type="text/javascript">
document.write("Hello World!");
</script>
</body>
</html>
Where Did you Put your
Scripts
 You can have any number of scripts
 Scripts can be placed in the HEAD or in the BODY
 In the HEAD, scripts are run before the page is
displayed
 In the BODY, scripts are run as the page is
displayed
 In the HEAD is the right place to define functions
and variables that are used by scripts within the
BODY
JavaScript Variables
 JavaScript has variables that you can declare
with the optional var keyword
 Variables declared within a function are local to
that function
 Variables declared outside of any function are
global variables
var myname = “vithu";
JavaScript Operators and
Constructs
 JavaScript has most of the operators we're used
to from C/Java
– Arithmetic (+, - , *, /, %)
– Assignment (=, +=, -=, *= /=, %=, ++, --)
– Logical (&&, ||, !)
– Comparison (<, >, <=, >=, ==)
Note: + also does string concatenation
 Constructs:
– if, else, while, for, switch, case
Simple User Interaction
 There are three built-in methods of doing simple
user interaction
 alert("There's a monster on the wing!");
o Alert something
 confirm("Are you sure you want to do that?");
o Asks the user to confirm
 prompt("Enter you name", "Adam");
o Asks the user something
JavaScript Functions
 JavaScript lets you define functions using the
function keyword
 Functions can return values using the return
keyword
function showConfirm()
{
confirm("Are you sure you want to do that?");
}
JavaScript Arrays
 JavaScript has arrays that are indexed starting at
0
 Special version of for works with arrays
 <script type="text/javascript">
 var colors = new Array();
 colors[0] = "red"; colors[1] = "green";
 colors[2] = "blue"; colors[3] = "orange";
 colors[4] = "magenta"; colors[5] = "cyan";
 for (var i in colors) {
 document.write("<div style="background-color:"
 + colors[i] + ";">"
 + colors[i] + "</div>n");
 }
 </script>
JavaScript Events
 Common Events:
– onload and onunload : when a page is first visited or
left
– onfocus, onblur, onchange : events pertaining to form
elements
– onsubmit : when a form is submitted
– onmouseover, onmouseout : for "menu effects"
Exception Handling
 JavaScript also has try, catch, and throw
keywords for handling JavaScript errors
try {
runSomeCode();
}
catch(err) {
var txt="There was an error on this page.nn"
+ "Error description: "
+ err.description + "nn"
alert(txt)
}
Comments in JavaScript
 Comments in JavaScript are delimited with // and
/* */ as in Java and C++
References
 http://cglab.ca/~morin/teaching/2405/notes/javasc
ript1.pdf
 www.w3schools.com/js/default.asp

More Related Content

What's hot

Java Script An Introduction By HWA
Java Script An Introduction By HWAJava Script An Introduction By HWA
Java Script An Introduction By HWAEmma Wood
 
Java script Learn Easy
Java script Learn Easy Java script Learn Easy
Java script Learn Easy prince Loffar
 
JavaScript Introduction and Implementation
JavaScript Introduction and ImplementationJavaScript Introduction and Implementation
JavaScript Introduction and ImplementationMaher Hossain
 
Using shortcode in plugin development
Using shortcode in plugin developmentUsing shortcode in plugin development
Using shortcode in plugin developmentgskhanal
 
Js placement
Js placementJs placement
Js placementSireesh K
 
Coder Presentation
Coder  PresentationCoder  Presentation
Coder PresentationDoug Green
 
React.js触ってみた 吉澤和香奈
React.js触ってみた 吉澤和香奈React.js触ってみた 吉澤和香奈
React.js触ってみた 吉澤和香奈Wakana Yoshizawa
 
Haml in 5 minutes
Haml in 5 minutesHaml in 5 minutes
Haml in 5 minutescameronbot
 
Ch2(working with forms)
Ch2(working with forms)Ch2(working with forms)
Ch2(working with forms)Chhom Karath
 
Java script Session No 1
Java script Session No 1Java script Session No 1
Java script Session No 1Saif Ullah Dar
 
Rethink Frontend Development With Elm
Rethink Frontend Development With ElmRethink Frontend Development With Elm
Rethink Frontend Development With ElmBrian Hogan
 

What's hot (20)

Javascript
JavascriptJavascript
Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Java Script An Introduction By HWA
Java Script An Introduction By HWAJava Script An Introduction By HWA
Java Script An Introduction By HWA
 
Java script Learn Easy
Java script Learn Easy Java script Learn Easy
Java script Learn Easy
 
JavaScript Introduction and Implementation
JavaScript Introduction and ImplementationJavaScript Introduction and Implementation
JavaScript Introduction and Implementation
 
Using shortcode in plugin development
Using shortcode in plugin developmentUsing shortcode in plugin development
Using shortcode in plugin development
 
Js placement
Js placementJs placement
Js placement
 
Java script
Java scriptJava script
Java script
 
Coder Presentation
Coder  PresentationCoder  Presentation
Coder Presentation
 
Begin scripting
Begin scriptingBegin scripting
Begin scripting
 
React.js触ってみた 吉澤和香奈
React.js触ってみた 吉澤和香奈React.js触ってみた 吉澤和香奈
React.js触ってみた 吉澤和香奈
 
programming
programmingprogramming
programming
 
Javascript tutorial
Javascript tutorialJavascript tutorial
Javascript tutorial
 
Html JavaScript and CSS
Html JavaScript and CSSHtml JavaScript and CSS
Html JavaScript and CSS
 
Javascript by geetanjali
Javascript by geetanjaliJavascript by geetanjali
Javascript by geetanjali
 
Haml in 5 minutes
Haml in 5 minutesHaml in 5 minutes
Haml in 5 minutes
 
Ch2(working with forms)
Ch2(working with forms)Ch2(working with forms)
Ch2(working with forms)
 
Java script Session No 1
Java script Session No 1Java script Session No 1
Java script Session No 1
 
JavaScript - Part-1
JavaScript - Part-1JavaScript - Part-1
JavaScript - Part-1
 
Rethink Frontend Development With Elm
Rethink Frontend Development With ElmRethink Frontend Development With Elm
Rethink Frontend Development With Elm
 

Viewers also liked

Java script introducation & basics
Java script introducation & basicsJava script introducation & basics
Java script introducation & basicsH K
 
javascript3
javascript3javascript3
javascript3osman do
 
[Basic HTML/CSS] 6. css - box sizing, display, margin, padding
[Basic HTML/CSS] 6. css - box sizing, display, margin, padding[Basic HTML/CSS] 6. css - box sizing, display, margin, padding
[Basic HTML/CSS] 6. css - box sizing, display, margin, paddingHyejin Oh
 
[CSS Drawing] Basic Tutorial (라이언 그리기)
[CSS Drawing] Basic Tutorial (라이언 그리기)[CSS Drawing] Basic Tutorial (라이언 그리기)
[CSS Drawing] Basic Tutorial (라이언 그리기)Hyejin Oh
 
PROGRESS - CSS BASIC
PROGRESS - CSS BASICPROGRESS - CSS BASIC
PROGRESS - CSS BASICUKM PROGRESS
 
[Basic HTML/CSS] 7. project
[Basic HTML/CSS] 7. project[Basic HTML/CSS] 7. project
[Basic HTML/CSS] 7. projectHyejin Oh
 
Web engineering - HTML Form
Web engineering -  HTML FormWeb engineering -  HTML Form
Web engineering - HTML FormNosheen Qamar
 
[Basic HTML/CSS] 4. html - form tags
[Basic HTML/CSS] 4. html - form tags[Basic HTML/CSS] 4. html - form tags
[Basic HTML/CSS] 4. html - form tagsHyejin Oh
 
[Basic HTML/CSS] 3. html - table tags
[Basic HTML/CSS] 3. html - table tags[Basic HTML/CSS] 3. html - table tags
[Basic HTML/CSS] 3. html - table tagsHyejin Oh
 
C++ to java
C++ to javaC++ to java
C++ to javaAjmal Ak
 
Dot net guide for beginner
Dot net guide for beginner Dot net guide for beginner
Dot net guide for beginner jayc8586
 
Beginning Java for .NET developers
Beginning Java for .NET developersBeginning Java for .NET developers
Beginning Java for .NET developersAndrei Rinea
 

Viewers also liked (20)

Java script introducation & basics
Java script introducation & basicsJava script introducation & basics
Java script introducation & basics
 
javascript3
javascript3javascript3
javascript3
 
[Basic HTML/CSS] 6. css - box sizing, display, margin, padding
[Basic HTML/CSS] 6. css - box sizing, display, margin, padding[Basic HTML/CSS] 6. css - box sizing, display, margin, padding
[Basic HTML/CSS] 6. css - box sizing, display, margin, padding
 
[CSS Drawing] Basic Tutorial (라이언 그리기)
[CSS Drawing] Basic Tutorial (라이언 그리기)[CSS Drawing] Basic Tutorial (라이언 그리기)
[CSS Drawing] Basic Tutorial (라이언 그리기)
 
PROGRESS - CSS BASIC
PROGRESS - CSS BASICPROGRESS - CSS BASIC
PROGRESS - CSS BASIC
 
[Basic HTML/CSS] 7. project
[Basic HTML/CSS] 7. project[Basic HTML/CSS] 7. project
[Basic HTML/CSS] 7. project
 
Web engineering - HTML Form
Web engineering -  HTML FormWeb engineering -  HTML Form
Web engineering - HTML Form
 
HTML Dasar : #10 Form
HTML Dasar : #10 FormHTML Dasar : #10 Form
HTML Dasar : #10 Form
 
[Basic HTML/CSS] 4. html - form tags
[Basic HTML/CSS] 4. html - form tags[Basic HTML/CSS] 4. html - form tags
[Basic HTML/CSS] 4. html - form tags
 
[Basic HTML/CSS] 3. html - table tags
[Basic HTML/CSS] 3. html - table tags[Basic HTML/CSS] 3. html - table tags
[Basic HTML/CSS] 3. html - table tags
 
Basic css-tutorial
Basic css-tutorialBasic css-tutorial
Basic css-tutorial
 
Basic css
Basic cssBasic css
Basic css
 
DAMS
DAMSDAMS
DAMS
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Python basic
Python basicPython basic
Python basic
 
C++ to java
C++ to javaC++ to java
C++ to java
 
Dot net guide for beginner
Dot net guide for beginner Dot net guide for beginner
Dot net guide for beginner
 
C sharp
C sharpC sharp
C sharp
 
3rd june
3rd june3rd june
3rd june
 
Beginning Java for .NET developers
Beginning Java for .NET developersBeginning Java for .NET developers
Beginning Java for .NET developers
 

Similar to Java script basic

Similar to Java script basic (20)

Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
 
Java script
Java scriptJava script
Java script
 
Java script
Java scriptJava script
Java script
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript Programming
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Scripting Oracle Develop 2007
Scripting Oracle Develop 2007
 
Java script
Java scriptJava script
Java script
 
Final Java-script.pptx
Final Java-script.pptxFinal Java-script.pptx
Final Java-script.pptx
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
 
Intro to Javascript and jQuery
Intro to Javascript and jQueryIntro to Javascript and jQuery
Intro to Javascript and jQuery
 
JavaScript Jump Start
JavaScript Jump StartJavaScript Jump Start
JavaScript Jump Start
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation
 
WEB TECHNOLOGIES JavaScript
WEB TECHNOLOGIES JavaScriptWEB TECHNOLOGIES JavaScript
WEB TECHNOLOGIES JavaScript
 
wp-UNIT_III.pptx
wp-UNIT_III.pptxwp-UNIT_III.pptx
wp-UNIT_III.pptx
 

Recently uploaded

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 

Recently uploaded (20)

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 

Java script basic

  • 2. What is JS?  JavaScript is the programming language of HTML and the Web.
  • 3. Introduction  Its Free and (NO) need engine  Simple and Easy to learn  Lightweight and Fast to code  Front & Back side coverage  Third party library  Growth community and docs
  • 4. JS General format <html> <head> <title>Hello World in JavaScript</title> </head> <body> <script type="text/javascript"> document.write("Hello World!"); </script> </body> </html>
  • 5. Where Did you Put your Scripts  You can have any number of scripts  Scripts can be placed in the HEAD or in the BODY  In the HEAD, scripts are run before the page is displayed  In the BODY, scripts are run as the page is displayed  In the HEAD is the right place to define functions and variables that are used by scripts within the BODY
  • 6. JavaScript Variables  JavaScript has variables that you can declare with the optional var keyword  Variables declared within a function are local to that function  Variables declared outside of any function are global variables var myname = “vithu";
  • 7. JavaScript Operators and Constructs  JavaScript has most of the operators we're used to from C/Java – Arithmetic (+, - , *, /, %) – Assignment (=, +=, -=, *= /=, %=, ++, --) – Logical (&&, ||, !) – Comparison (<, >, <=, >=, ==) Note: + also does string concatenation  Constructs: – if, else, while, for, switch, case
  • 8. Simple User Interaction  There are three built-in methods of doing simple user interaction  alert("There's a monster on the wing!"); o Alert something  confirm("Are you sure you want to do that?"); o Asks the user to confirm  prompt("Enter you name", "Adam"); o Asks the user something
  • 9. JavaScript Functions  JavaScript lets you define functions using the function keyword  Functions can return values using the return keyword function showConfirm() { confirm("Are you sure you want to do that?"); }
  • 10. JavaScript Arrays  JavaScript has arrays that are indexed starting at 0  Special version of for works with arrays
  • 11.  <script type="text/javascript">  var colors = new Array();  colors[0] = "red"; colors[1] = "green";  colors[2] = "blue"; colors[3] = "orange";  colors[4] = "magenta"; colors[5] = "cyan";  for (var i in colors) {  document.write("<div style="background-color:"  + colors[i] + ";">"  + colors[i] + "</div>n");  }  </script>
  • 12. JavaScript Events  Common Events: – onload and onunload : when a page is first visited or left – onfocus, onblur, onchange : events pertaining to form elements – onsubmit : when a form is submitted – onmouseover, onmouseout : for "menu effects"
  • 13. Exception Handling  JavaScript also has try, catch, and throw keywords for handling JavaScript errors try { runSomeCode(); } catch(err) { var txt="There was an error on this page.nn" + "Error description: " + err.description + "nn" alert(txt) }
  • 14. Comments in JavaScript  Comments in JavaScript are delimited with // and /* */ as in Java and C++