SlideShare a Scribd company logo
1 of 24
Z
Week 11:
Introduction to
JavaScript
Subject Code: COMP121
By: Marlon Jamera
Email: mbjamera@ama.edu.ph
Z
Introduction to
JavaScript
Z
Scope of the Lesson
• Introduction to JavaScript
• Using JavaScript Code
• Using External Script File
• JavaScript Syntax
• Data Types
• Objects
• String Operations
• Standard Popup Boxes
• JavaScript Functions
Z
Learning Outcomes
By the end of the lesson, you will be
familiar and know how the website works
using JavaScripts.
• Discuss the introduction to JavaScript
and using JavaScript codes.
• Understand the coding syntax using
external script file and JavaScript syntax.
• Explain thoroughly the coding styles of
objects and string operations.
Z
Introduction to JavaScript
• JavaScript is a front-end scripting
language developed by Netscape for
dynamic content.
• Lightweight, but with limited
capabilities.
• Can be used as object-oriented
language.
• Client-side Technology
• Embedded in your HTML page.
• Interpreted by the web browser.
Z
Introduction to JavaScript
• JavaScript allows interactivity such as:
• Implementing form validation.
• React to user actions, e.g handle keys.
• Changing an image on moving mouse
over it.
• Sections of a page appearing and
disappearing.
• Performing complex calculation.
• Custom HTML controls like
scrollable table.
Z
Introduction to JavaScript
• What can JavaScript do?
• Can handle events
• Can read and write HTML elements
and modify the DOM tree
• Can validate form data
• Can access / modify browser cookies
• Can detect the user’s browser and OS
• Can be used as object-oriented
language
• Can handle exceptions.
Z
Introduction to JavaScript
• The first script
<html>
<body>
<script type="text/javascript">
alert('Hello JavaScript!');
</script>
</body>
</html>
Z
Introduction to JavaScript
• The first script
<html>
<body>
<script type="text/javascript">
alert('Hello JavaScript!');
</script>
</body>
</html>
Z
Introduction to JavaScript
• Another script
<html>
<body>
<script type="text/javascript">
document.write('JavaScript
rulez!');
</script>
</body>
</html>
Z
Introduction to JavaScript
• Another script
<html>
<body>
<script type="text/javascript">
document.write('JavaScript
rules!');
</script>
</body>
</html>
Z
Using JavaScript Code
• The JavaScript code can be placed in:
• <script> tag in head
• <script> tag in the body
• External files, linked via <script> tag
head
• Files usually have .js extension
• Highly recommended
• The .js files get cached by the
browser
<script src="scripts.js" type="text/javscript">
<!– code placed here will not be executed! -->
</script>
Z
JavaScript – When is executed?
• JavaScript code is executed during the
page load or when the browser fires an
event.
• All statements are executed at page
loading
• Some statements just define functions
that can be called later.
• Function calls or code can be attached as
“event handlers” via tag attributes
• Executed when the event fired by the
browser
Z
Using External Script Files
<html>
<head>
<script src="sample.js" type="text/javascript">
</script>
</head>
<body>
<button onclick="sample()" value="Call
JavaScript
function from sample.js" />
</body>
</html>
• Using external script files:
• External JavaScript File:
function sample() {
alert('Hello from sample.js!')
}
Z
Using External Script Files
<html>
<head>
<script src="sample.js" type="text/javascript">
</script>
</head>
<body>
<button onclick="sample()" value="Call
JavaScript
function from sample.js" />
</body>
</html>
• Using external script files:
• External JavaScript File:
function sample() {
alert('Hello from sample.js!')
}
The <script> tag is always empty.
Z
JavaScript Syntax
• The JavaScript syntax is similar to C#
and Java.
• Operators (+, - , * , =, !=, &&, ++ …)
• Variables (typeless)
• Conditional statements (if, else)
• Loops (for, while)
• Arrays
• Functions (can return value)
Z
Operand and Operators
• The numbers in an arithmetic operations
are called operands.
• The operation to be performed between
two operands is defined by operator.
<script>
var x = 10;
var y = 5;
document.getElementById("demo").innerHTML = x
* y;
</script>
Z
Data Types
• The JavaScript data types:
• Numbers (integer, floating-point)
• Boolean (true / false)
• String type – string of characters
• Arrays
var myName = "You can use both single or
double quotes for strings";
var my_array = [1, 5.3, "aaa"];
Z
Everything is Object
• Every variable can be considered as
object
• For example, strings and arrays have
member functions:
var test = "some string";
alert(test[7]); // shows letter 'r'
alert(test.charAt(5)); // shows letter 's'
var arr = [1,3,4];
alert (arr.length); // shows 3
arr.push(7); // appends 7 to end of array
alert (arr[3]); // shows 7
Z
String Operations
• The + operator joins strings
• What is “9” + 9?
• Converting string to number:
string1 = "fat ";
string2 = "cats";
alert(string1 + string2); // fat cats
alert("9" + 9); // 99
alert(parseInt("9") + 9); // 18
Z
Standard Popup Boxes
• Alert box with text and [ok] button
• Just a message in a dialog box:
• Confirmation box
• Contains text, ok and cancel button.
• Prompt box:
• Contains text, input field with value.
alert("Some text here");
confirm("Are you sure?");
prompt ("enter amount", 10);
Z
JavaScript Functions
• A JavaScript function is a block of code
designed to perform a particular task.
• A JavaScript function is executed when
“something” invokes it (calls it).
<p id="demo"></p>
<script>
function myFunction(a, b) {
return a * b;
}
document.getElementById("demo").innerHTML =
myFunction(4, 3);
</script>
Z
JavaScript Functions
<html>
<head>
<script type="text/javascript">
function test (message) {
alert(message);
}
</script>
</head>
<body>
<img src="logo.gif"
onclick="test('clicked!')" />
</body>
</html>
Z
Let’s call it a day,
Thank you!

More Related Content

What's hot (20)

Css types internal, external and inline (1)
Css types internal, external and inline (1)Css types internal, external and inline (1)
Css types internal, external and inline (1)
 
Introduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptIntroduction to JavaScript (1).ppt
Introduction to JavaScript (1).ppt
 
Javascript
JavascriptJavascript
Javascript
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Html images syntax
Html images syntaxHtml images syntax
Html images syntax
 
Jquery
JqueryJquery
Jquery
 
Java script
Java scriptJava script
Java script
 
HTML (Web) basics for a beginner
HTML (Web) basics for a beginnerHTML (Web) basics for a beginner
HTML (Web) basics for a beginner
 
Html frames
Html framesHtml frames
Html frames
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Java script
Java scriptJava script
Java script
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Html forms
Html formsHtml forms
Html forms
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Advance HTML
Advance HTMLAdvance HTML
Advance HTML
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Javascript
JavascriptJavascript
Javascript
 
HTML5 - Forms
HTML5 - FormsHTML5 - Forms
HTML5 - Forms
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 

Similar to Introduction to JavaScript

Similar to Introduction to JavaScript (20)

BITM3730Week6.pptx
BITM3730Week6.pptxBITM3730Week6.pptx
BITM3730Week6.pptx
 
Final Java-script.pptx
Final Java-script.pptxFinal Java-script.pptx
Final Java-script.pptx
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
 
Java script
Java scriptJava script
Java script
 
BITM3730 10-3.pptx
BITM3730 10-3.pptxBITM3730 10-3.pptx
BITM3730 10-3.pptx
 
BITM3730 10-4.pptx
BITM3730 10-4.pptxBITM3730 10-4.pptx
BITM3730 10-4.pptx
 
javascriptPresentation.pdf
javascriptPresentation.pdfjavascriptPresentation.pdf
javascriptPresentation.pdf
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
 
Lecture 5 javascript
Lecture 5 javascriptLecture 5 javascript
Lecture 5 javascript
 
Unit 4(it workshop)
Unit 4(it workshop)Unit 4(it workshop)
Unit 4(it workshop)
 
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
 
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
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
 
Java script
Java scriptJava script
Java script
 
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and ScriptingIT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
 
Javascript
JavascriptJavascript
Javascript
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript!
JavaScript!JavaScript!
JavaScript!
 

More from Marlon Jamera

JavaScript Conditional Statements
JavaScript Conditional StatementsJavaScript Conditional Statements
JavaScript Conditional StatementsMarlon Jamera
 
Tables and Forms in HTML
Tables and Forms in HTMLTables and Forms in HTML
Tables and Forms in HTMLMarlon Jamera
 
Images and Lists in HTML
Images and Lists in HTMLImages and Lists in HTML
Images and Lists in HTMLMarlon Jamera
 
Trends in the Database
Trends in the DatabaseTrends in the Database
Trends in the DatabaseMarlon Jamera
 
Trends in Database Management
Trends in Database ManagementTrends in Database Management
Trends in Database ManagementMarlon Jamera
 
How the Web Works Using HTML
How the Web Works Using HTMLHow the Web Works Using HTML
How the Web Works Using HTMLMarlon Jamera
 
Basic Concept of Database
Basic Concept of DatabaseBasic Concept of Database
Basic Concept of DatabaseMarlon Jamera
 
Website Basics and Categories
Website Basics and CategoriesWebsite Basics and Categories
Website Basics and CategoriesMarlon Jamera
 
Trends In Telecommunications
Trends In TelecommunicationsTrends In Telecommunications
Trends In TelecommunicationsMarlon Jamera
 
Hardware Technology Trends
Hardware Technology TrendsHardware Technology Trends
Hardware Technology TrendsMarlon Jamera
 
Familiarization with Web Tools
Familiarization with Web ToolsFamiliarization with Web Tools
Familiarization with Web ToolsMarlon Jamera
 
Internet Applications
Internet ApplicationsInternet Applications
Internet ApplicationsMarlon Jamera
 
Introduction to World Wide Web
Introduction to World Wide WebIntroduction to World Wide Web
Introduction to World Wide WebMarlon Jamera
 

More from Marlon Jamera (17)

JavaScript Conditional Statements
JavaScript Conditional StatementsJavaScript Conditional Statements
JavaScript Conditional Statements
 
Tables and Forms in HTML
Tables and Forms in HTMLTables and Forms in HTML
Tables and Forms in HTML
 
Images and Lists in HTML
Images and Lists in HTMLImages and Lists in HTML
Images and Lists in HTML
 
ICT in Society
ICT in SocietyICT in Society
ICT in Society
 
ICT in Business
ICT in BusinessICT in Business
ICT in Business
 
The Future of ICT
The Future of ICTThe Future of ICT
The Future of ICT
 
Trends in the Database
Trends in the DatabaseTrends in the Database
Trends in the Database
 
Trends in Database Management
Trends in Database ManagementTrends in Database Management
Trends in Database Management
 
How the Web Works Using HTML
How the Web Works Using HTMLHow the Web Works Using HTML
How the Web Works Using HTML
 
Basic Concept of Database
Basic Concept of DatabaseBasic Concept of Database
Basic Concept of Database
 
Website Basics and Categories
Website Basics and CategoriesWebsite Basics and Categories
Website Basics and Categories
 
Trends In Telecommunications
Trends In TelecommunicationsTrends In Telecommunications
Trends In Telecommunications
 
Software Trends
Software TrendsSoftware Trends
Software Trends
 
Hardware Technology Trends
Hardware Technology TrendsHardware Technology Trends
Hardware Technology Trends
 
Familiarization with Web Tools
Familiarization with Web ToolsFamiliarization with Web Tools
Familiarization with Web Tools
 
Internet Applications
Internet ApplicationsInternet Applications
Internet Applications
 
Introduction to World Wide Web
Introduction to World Wide WebIntroduction to World Wide Web
Introduction to World Wide Web
 

Recently uploaded

2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge GraphsEleniIlkou
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiMonica Sydney
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"growthgrids
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtrahman018755
 
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...meghakumariji156
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasDigicorns Technologies
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查ydyuyu
 
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime BalliaBallia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Balliameghakumariji156
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制pxcywzqs
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样ayvbos
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...gajnagarg
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样ayvbos
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理F
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoilmeghakumariji156
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查ydyuyu
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...kumargunjan9515
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsPriya Reddy
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdfMatthew Sinclair
 

Recently uploaded (20)

2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime BalliaBallia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 

Introduction to JavaScript

  • 1. Z Week 11: Introduction to JavaScript Subject Code: COMP121 By: Marlon Jamera Email: mbjamera@ama.edu.ph
  • 3. Z Scope of the Lesson • Introduction to JavaScript • Using JavaScript Code • Using External Script File • JavaScript Syntax • Data Types • Objects • String Operations • Standard Popup Boxes • JavaScript Functions
  • 4. Z Learning Outcomes By the end of the lesson, you will be familiar and know how the website works using JavaScripts. • Discuss the introduction to JavaScript and using JavaScript codes. • Understand the coding syntax using external script file and JavaScript syntax. • Explain thoroughly the coding styles of objects and string operations.
  • 5. Z Introduction to JavaScript • JavaScript is a front-end scripting language developed by Netscape for dynamic content. • Lightweight, but with limited capabilities. • Can be used as object-oriented language. • Client-side Technology • Embedded in your HTML page. • Interpreted by the web browser.
  • 6. Z Introduction to JavaScript • JavaScript allows interactivity such as: • Implementing form validation. • React to user actions, e.g handle keys. • Changing an image on moving mouse over it. • Sections of a page appearing and disappearing. • Performing complex calculation. • Custom HTML controls like scrollable table.
  • 7. Z Introduction to JavaScript • What can JavaScript do? • Can handle events • Can read and write HTML elements and modify the DOM tree • Can validate form data • Can access / modify browser cookies • Can detect the user’s browser and OS • Can be used as object-oriented language • Can handle exceptions.
  • 8. Z Introduction to JavaScript • The first script <html> <body> <script type="text/javascript"> alert('Hello JavaScript!'); </script> </body> </html>
  • 9. Z Introduction to JavaScript • The first script <html> <body> <script type="text/javascript"> alert('Hello JavaScript!'); </script> </body> </html>
  • 10. Z Introduction to JavaScript • Another script <html> <body> <script type="text/javascript"> document.write('JavaScript rulez!'); </script> </body> </html>
  • 11. Z Introduction to JavaScript • Another script <html> <body> <script type="text/javascript"> document.write('JavaScript rules!'); </script> </body> </html>
  • 12. Z Using JavaScript Code • The JavaScript code can be placed in: • <script> tag in head • <script> tag in the body • External files, linked via <script> tag head • Files usually have .js extension • Highly recommended • The .js files get cached by the browser <script src="scripts.js" type="text/javscript"> <!– code placed here will not be executed! --> </script>
  • 13. Z JavaScript – When is executed? • JavaScript code is executed during the page load or when the browser fires an event. • All statements are executed at page loading • Some statements just define functions that can be called later. • Function calls or code can be attached as “event handlers” via tag attributes • Executed when the event fired by the browser
  • 14. Z Using External Script Files <html> <head> <script src="sample.js" type="text/javascript"> </script> </head> <body> <button onclick="sample()" value="Call JavaScript function from sample.js" /> </body> </html> • Using external script files: • External JavaScript File: function sample() { alert('Hello from sample.js!') }
  • 15. Z Using External Script Files <html> <head> <script src="sample.js" type="text/javascript"> </script> </head> <body> <button onclick="sample()" value="Call JavaScript function from sample.js" /> </body> </html> • Using external script files: • External JavaScript File: function sample() { alert('Hello from sample.js!') } The <script> tag is always empty.
  • 16. Z JavaScript Syntax • The JavaScript syntax is similar to C# and Java. • Operators (+, - , * , =, !=, &&, ++ …) • Variables (typeless) • Conditional statements (if, else) • Loops (for, while) • Arrays • Functions (can return value)
  • 17. Z Operand and Operators • The numbers in an arithmetic operations are called operands. • The operation to be performed between two operands is defined by operator. <script> var x = 10; var y = 5; document.getElementById("demo").innerHTML = x * y; </script>
  • 18. Z Data Types • The JavaScript data types: • Numbers (integer, floating-point) • Boolean (true / false) • String type – string of characters • Arrays var myName = "You can use both single or double quotes for strings"; var my_array = [1, 5.3, "aaa"];
  • 19. Z Everything is Object • Every variable can be considered as object • For example, strings and arrays have member functions: var test = "some string"; alert(test[7]); // shows letter 'r' alert(test.charAt(5)); // shows letter 's' var arr = [1,3,4]; alert (arr.length); // shows 3 arr.push(7); // appends 7 to end of array alert (arr[3]); // shows 7
  • 20. Z String Operations • The + operator joins strings • What is “9” + 9? • Converting string to number: string1 = "fat "; string2 = "cats"; alert(string1 + string2); // fat cats alert("9" + 9); // 99 alert(parseInt("9") + 9); // 18
  • 21. Z Standard Popup Boxes • Alert box with text and [ok] button • Just a message in a dialog box: • Confirmation box • Contains text, ok and cancel button. • Prompt box: • Contains text, input field with value. alert("Some text here"); confirm("Are you sure?"); prompt ("enter amount", 10);
  • 22. Z JavaScript Functions • A JavaScript function is a block of code designed to perform a particular task. • A JavaScript function is executed when “something” invokes it (calls it). <p id="demo"></p> <script> function myFunction(a, b) { return a * b; } document.getElementById("demo").innerHTML = myFunction(4, 3); </script>
  • 23. Z JavaScript Functions <html> <head> <script type="text/javascript"> function test (message) { alert(message); } </script> </head> <body> <img src="logo.gif" onclick="test('clicked!')" /> </body> </html>
  • 24. Z Let’s call it a day, Thank you!

Editor's Notes

  1. Left angle bracket < Right angle bracket >
  2. http://www.tizag.com/javascriptT/javascriptevents.php