SlideShare a Scribd company logo
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

javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
sentayehu
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
Bedis ElAchèche
 
Java script
Java scriptJava script
Java script
Sadeek Mohammed
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
shreesenthil
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Taha Malampatti
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
WebStackAcademy
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
Priya Goyal
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
Knoldus Inc.
 
Javascript
JavascriptJavascript
Javascript
Nagarajan
 
Java script
Java scriptJava script
Java script
Shyam Khant
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
Walid Ashraf
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
ShahDhruv21
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Functions in javascript
Functions in javascriptFunctions in javascript
Javascript functions
Javascript functionsJavascript functions
Javascript functions
Alaref Abushaala
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
WebStackAcademy
 

What's hot (20)

javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
Java script
Java scriptJava script
Java script
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
Javascript
JavascriptJavascript
Javascript
 
Java script
Java scriptJava script
Java script
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Js ppt
Js pptJs ppt
Js ppt
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Php basics
Php basicsPhp basics
Php basics
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Functions in javascript
Functions in javascriptFunctions in javascript
Functions in javascript
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 

Similar to Introduction to JavaScript

BITM3730Week6.pptx
BITM3730Week6.pptxBITM3730Week6.pptx
BITM3730Week6.pptx
MattMarino13
 
Final Java-script.pptx
Final Java-script.pptxFinal Java-script.pptx
Final Java-script.pptx
AlkanthiSomesh
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
koppenolski
 
Java script
Java scriptJava script
Java script
Jay Patel
 
BITM3730 10-3.pptx
BITM3730 10-3.pptxBITM3730 10-3.pptx
BITM3730 10-3.pptx
MattMarino13
 
BITM3730 10-4.pptx
BITM3730 10-4.pptxBITM3730 10-4.pptx
BITM3730 10-4.pptx
MattMarino13
 
javascriptPresentation.pdf
javascriptPresentation.pdfjavascriptPresentation.pdf
javascriptPresentation.pdf
wildcat9335
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
sandeshshahapur
 
Lecture 5 javascript
Lecture 5 javascriptLecture 5 javascript
Lecture 5 javascript
Mujtaba Haider
 
Unit 4(it workshop)
Unit 4(it workshop)Unit 4(it workshop)
Unit 4(it workshop)
Dr.Lokesh Gagnani
 
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
Syed Moosa Kaleem
 
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
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
rashmiisrani1
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJamshid Hashimi
 
Java script
Java scriptJava script
Java script
vishal choudhary
 
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
pkaviya
 
Javascript
JavascriptJavascript
Javascript
Mozxai
 
Javascript
JavascriptJavascript

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
 
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 side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
 
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
 
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
 

More from Marlon Jamera

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

History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
laozhuseo02
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Sanjeev Rampal
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
Gal Baras
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
JungkooksNonexistent
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 
Output determination SAP S4 HANA SAP SD CC
Output determination SAP S4 HANA SAP SD CCOutput determination SAP S4 HANA SAP SD CC
Output determination SAP S4 HANA SAP SD CC
ShahulHameed54211
 
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptxLiving-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
TristanJasperRamos
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
JeyaPerumal1
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
3ipehhoa
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
laozhuseo02
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
Himani415946
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
nirahealhty
 

Recently uploaded (16)

History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 
Output determination SAP S4 HANA SAP SD CC
Output determination SAP S4 HANA SAP SD CCOutput determination SAP S4 HANA SAP SD CC
Output determination SAP S4 HANA SAP SD CC
 
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptxLiving-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
 

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