SlideShare a Scribd company logo
Introduction to
JavaScript
2
Topics
 What is JavaScript?
 Why JavaScript?
 Including JavaScript in HTML
 Hello World Example Script
 JavaScript Comments
3
What is JavaScript?
 Created by Netscape
 Originally called LiveWire then LiveScript
 A client-side scripting language
 Client-side refers to the fact that it is executed in
the client (software) that the viewer is using. In
the case of JavaScript, the client is the browser.
 A server-side language is one that runs on the
Web server. Examples: PHP, Python
 Interpreted on-the-fly by the client
 Each line is processed as it loads in the browser
4
JavaScript is not Java
 Completely different types of languages that
just happen to be similarly named
 JavaScript - programs are interpreted in the
browser
 Java - programs are compiled and can be run as
stand alone applications
5
Why JavaScript?
 It’s easier to learn than most programming
languages
 It allows you to make interactive Web pages
 It can be fun!
6
Including JavaScript in HTML
 Two ways to add JavaScript to Web pages
 Use the <script>…</script> tag
 Include the script in an external file -- more about
this later in the semester
 Initially, we will only use the <script>…</script>
tag
7
Hello, World!
 Typically, in any programming language, the
first example you learn displays “Hello,
World!”
 We are going to take a look at a Hello World
example and then examine all of its parts.
8
Hello World in JavaScript
<!DOCTYPE html>
<html>
<head>
<title>Hello World Example</title>
</head>
<body>
<script type="text/javascript">
<!--
document.write("<h1>Hello, world!</h1>");
//-->
</script>
</body>
</html>
9
Hello World Screenshot
10
The <script>…</script> tag
 The code for the script is contained in the
<script>…</script> tag
<script type="text/javascript">
.
.
.
</script>
11
Hiding JavaScript from Older
Browsers
 Some older browsers do not support JavaScript
 We need to tell those browsers to ignore what is in the
<script> tag
<script type="text/javascript">
<!--
some JavaScript code
//-->
</script>
12
Displaying text
 The document.write() method writes a string
of text to the browser
<script type="text/javascript">
<!--
document.write("<h1>Hello, world!</h1>");
//-->
</script>
13
document.write()
document.write("<h1>Hello,world!</h1>");
Enclosed in quotes --
denotes a "string"
Ends in a semicolon
14
Comments in JavaScript
 Two types of comments
 Single line
 Uses two forward slashes (i.e. //)
 Multiple line
 Uses /* and */
15
Single Line Comment Example
<script type="text/javascript">
<!--
// This is my JavaScript comment
document.write("<h1>Hello!</h1>");
//-->
</script>
16
Multiple Line Comment
Example
<script type="text/javascript">
<!--
/* This is a multiple line comment.
* The star at the beginning of this line is optional.
* So is the star at the beginning of this line.
*/
document.write("<h1>Hello!</h1>");
//-->
</script>
17
Find the Bug!
<script type="text/javascript">
<!--
/* This is my JavaScript comment
* that spans more than 1 line.
*
document.write("<h1>Hello!</h1>");
//-->
</script>

More Related Content

PPT
JavaScript (1).pptdffdfvdfvfvfvfefwefedfe
PPT
javascript.ppt
PPT
JAVA SCRIPT
DOCX
Java script hello world
PDF
JS BASICS JAVA SCRIPT SCRIPTING
PPT
basics of javascript and fundamentals ppt
PPT
Javascript overview and introduction to js
PPT
JS-Slides-1 (1).ppt vbefgvsdfgdfgfggergertgrtgrtgt
JavaScript (1).pptdffdfvdfvfvfvfefwefedfe
javascript.ppt
JAVA SCRIPT
Java script hello world
JS BASICS JAVA SCRIPT SCRIPTING
basics of javascript and fundamentals ppt
Javascript overview and introduction to js
JS-Slides-1 (1).ppt vbefgvsdfgdfgfggergertgrtgrtgt

Similar to L08IntroToJavaScript.ppt (20)

PPT
JS-Slides_for_begineers_javascript-1.ppt
PPT
java script programming slide 1 from tn state
PDF
Java script how to
PPTX
Unit 4 Java script.pptx
PPT
JS-Slides-1hgvhfhgftgfvujguyghvhjbjbnnhg
DOC
2javascript web programming with JAVA script
DOCX
Javascript
PPTX
JavaScript New Tutorial Class XI and XII.pptx
PPT
Java script
PPT
Java script
DOC
Java script by Act Academy
PPT
Introduction to Java Scripting
PDF
Basic JavaScript Tutorial
PPTX
Java script Basic
DOC
Basics java scripts
PPTX
JavaScript_III.pptx
PPTX
Internet Based Programming -3-JAVASCRIPT
PDF
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
PDF
Web programming UNIT II by Bhavsingh Maloth
PPT
Javascript by geetanjali
JS-Slides_for_begineers_javascript-1.ppt
java script programming slide 1 from tn state
Java script how to
Unit 4 Java script.pptx
JS-Slides-1hgvhfhgftgfvujguyghvhjbjbnnhg
2javascript web programming with JAVA script
Javascript
JavaScript New Tutorial Class XI and XII.pptx
Java script
Java script
Java script by Act Academy
Introduction to Java Scripting
Basic JavaScript Tutorial
Java script Basic
Basics java scripts
JavaScript_III.pptx
Internet Based Programming -3-JAVASCRIPT
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
Web programming UNIT II by Bhavsingh Maloth
Javascript by geetanjali
Ad

Recently uploaded (20)

PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
Tartificialntelligence_presentation.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation theory and applications.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Getting Started with Data Integration: FME Form 101
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Approach and Philosophy of On baking technology
Programs and apps: productivity, graphics, security and other tools
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Machine learning based COVID-19 study performance prediction
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Tartificialntelligence_presentation.pptx
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation_ Review paper, used for researhc scholars
Digital-Transformation-Roadmap-for-Companies.pptx
A Presentation on Artificial Intelligence
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation theory and applications.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Getting Started with Data Integration: FME Form 101
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Approach and Philosophy of On baking technology
Ad

L08IntroToJavaScript.ppt

  • 2. 2 Topics  What is JavaScript?  Why JavaScript?  Including JavaScript in HTML  Hello World Example Script  JavaScript Comments
  • 3. 3 What is JavaScript?  Created by Netscape  Originally called LiveWire then LiveScript  A client-side scripting language  Client-side refers to the fact that it is executed in the client (software) that the viewer is using. In the case of JavaScript, the client is the browser.  A server-side language is one that runs on the Web server. Examples: PHP, Python  Interpreted on-the-fly by the client  Each line is processed as it loads in the browser
  • 4. 4 JavaScript is not Java  Completely different types of languages that just happen to be similarly named  JavaScript - programs are interpreted in the browser  Java - programs are compiled and can be run as stand alone applications
  • 5. 5 Why JavaScript?  It’s easier to learn than most programming languages  It allows you to make interactive Web pages  It can be fun!
  • 6. 6 Including JavaScript in HTML  Two ways to add JavaScript to Web pages  Use the <script>…</script> tag  Include the script in an external file -- more about this later in the semester  Initially, we will only use the <script>…</script> tag
  • 7. 7 Hello, World!  Typically, in any programming language, the first example you learn displays “Hello, World!”  We are going to take a look at a Hello World example and then examine all of its parts.
  • 8. 8 Hello World in JavaScript <!DOCTYPE html> <html> <head> <title>Hello World Example</title> </head> <body> <script type="text/javascript"> <!-- document.write("<h1>Hello, world!</h1>"); //--> </script> </body> </html>
  • 10. 10 The <script>…</script> tag  The code for the script is contained in the <script>…</script> tag <script type="text/javascript"> . . . </script>
  • 11. 11 Hiding JavaScript from Older Browsers  Some older browsers do not support JavaScript  We need to tell those browsers to ignore what is in the <script> tag <script type="text/javascript"> <!-- some JavaScript code //--> </script>
  • 12. 12 Displaying text  The document.write() method writes a string of text to the browser <script type="text/javascript"> <!-- document.write("<h1>Hello, world!</h1>"); //--> </script>
  • 14. 14 Comments in JavaScript  Two types of comments  Single line  Uses two forward slashes (i.e. //)  Multiple line  Uses /* and */
  • 15. 15 Single Line Comment Example <script type="text/javascript"> <!-- // This is my JavaScript comment document.write("<h1>Hello!</h1>"); //--> </script>
  • 16. 16 Multiple Line Comment Example <script type="text/javascript"> <!-- /* This is a multiple line comment. * The star at the beginning of this line is optional. * So is the star at the beginning of this line. */ document.write("<h1>Hello!</h1>"); //--> </script>
  • 17. 17 Find the Bug! <script type="text/javascript"> <!-- /* This is my JavaScript comment * that spans more than 1 line. * document.write("<h1>Hello!</h1>"); //--> </script>