7
Most read
22
Most read
23
Most read
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

PPTX
Basics of JAVA programming
PPT
Javascript
PPT
Js ppt
PDF
jQuery for beginners
PPTX
Event In JavaScript
PPTX
Lab #2: Introduction to Javascript
PDF
Introduction to HTML5
Basics of JAVA programming
Javascript
Js ppt
jQuery for beginners
Event In JavaScript
Lab #2: Introduction to Javascript
Introduction to HTML5

What's hot (20)

PPT
Java Presentation
PPTX
Reactjs
PPTX
HTML5 & CSS3
PPTX
Angularjs PPT
PPTX
Core java complete ppt(note)
PPTX
JAVA LOOP.pptx
PDF
JavaScript - Chapter 3 - Introduction
PPTX
Java script
PPT
JQuery introduction
PPTX
jQuery from the very beginning
PPT
Css Ppt
PPTX
presentation in html,css,javascript
PDF
JAVA PPT Part-1 BY ADI.pdf
PPTX
Client side scripting using Javascript
PPT
Java
PPTX
Java program structure
PPT
Eclipse introduction IDE PRESENTATION
PPTX
HTML, CSS, JavaScript for beginners
Java Presentation
Reactjs
HTML5 & CSS3
Angularjs PPT
Core java complete ppt(note)
JAVA LOOP.pptx
JavaScript - Chapter 3 - Introduction
Java script
JQuery introduction
jQuery from the very beginning
Css Ppt
presentation in html,css,javascript
JAVA PPT Part-1 BY ADI.pdf
Client side scripting using Javascript
Java
Java program structure
Eclipse introduction IDE PRESENTATION
HTML, CSS, JavaScript for beginners
Ad

Similar to Introduction to JavaScript (20)

PDF
WT UNIT 2 presentation :client side technologies JavaScript And Dom
PPT
PPTX
JavaScript lesson 1.pptx
PPTX
Javascript
PPTX
Web designing unit 4
PDF
Wt unit 2 ppts client sied technology
PDF
Wt unit 2 ppts client side technology
PPTX
UNIT 1 (7).pptx
PPTX
Introduction to JAVA SCRIPT USING HTML and CSS
PPTX
Learning About JavaScript (…and its little buddy, JQuery!)
PPTX
Lecture 5 javascript
PDF
javascriptPresentation.pdf
PPTX
Basics of Java Script (JS)
PDF
Client sidescripting javascript
PPTX
Welcome to React.pptx
PPTX
WT Module-3.pptx
PDF
Unit 4(it workshop)
PPTX
Javascript
PDF
Lecture 10.pdf
WT UNIT 2 presentation :client side technologies JavaScript And Dom
JavaScript lesson 1.pptx
Javascript
Web designing unit 4
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client side technology
UNIT 1 (7).pptx
Introduction to JAVA SCRIPT USING HTML and CSS
Learning About JavaScript (…and its little buddy, JQuery!)
Lecture 5 javascript
javascriptPresentation.pdf
Basics of Java Script (JS)
Client sidescripting javascript
Welcome to React.pptx
WT Module-3.pptx
Unit 4(it workshop)
Javascript
Lecture 10.pdf
Ad

More from Marlon Jamera (17)

PPTX
JavaScript Conditional Statements
PPTX
Tables and Forms in HTML
PPTX
Images and Lists in HTML
PPTX
ICT in Society
PPTX
ICT in Business
PPTX
The Future of ICT
PPTX
Trends in the Database
PPTX
Trends in Database Management
PPTX
How the Web Works Using HTML
PPTX
Basic Concept of Database
PPTX
Website Basics and Categories
PPTX
Trends In Telecommunications
PPTX
Software Trends
PPTX
Hardware Technology Trends
PPTX
Familiarization with Web Tools
PPTX
Internet Applications
PPTX
Introduction to World Wide Web
JavaScript Conditional Statements
Tables and Forms in HTML
Images and Lists in HTML
ICT in Society
ICT in Business
The Future of ICT
Trends in the Database
Trends in Database Management
How the Web Works Using HTML
Basic Concept of Database
Website Basics and Categories
Trends In Telecommunications
Software Trends
Hardware Technology Trends
Familiarization with Web Tools
Internet Applications
Introduction to World Wide Web

Recently uploaded (20)

PDF
How Technology Shapes Our Information Age
PPTX
Digital Project Mastery using Autodesk Docs Workshops
PDF
Tailieuhoctiengnhat.com__(N5) 1021 từ vựng tổng hợp.pdf
PDF
Technical SEO Explained: How To Make Your Website Search-Friendly
PDF
B2B Marketing mba class material for study
PPTX
c_languagew_structure_and_functions.pptx
DOCX
Audio to Video AI Technology Revolutiona
PPTX
北安普顿大学毕业证UoN成绩单GPA修改北安普顿大学i20学历认证文凭
PPTX
Chapter 1_Overview hhhhhhhhhhhhhhhhhhhhhhhhhh
PPTX
Introduction: Living in the IT ERA.pptx
PDF
AGENT SLOT TERPERCAYA INDONESIA – MAIN MUDAH, WD CEPAT, HANYA DI KANCA4D
PDF
Information Technology practical assignment
PPTX
FreePBX_Project_Presentation_With_Gantt.pptx
PPTX
Data Flows presentation hubspot crm.pptx
PPT
Expect The Impossiblesssssssssssssss.ppt
PPT
Comparison of 2 Population Kuch toh bhadwa chodi karwa raha
PPTX
IOT LECTURE IOT LECTURE IOT LECTURE IOT LECTURE
PDF
Lesson.-Reporting-and-Sharing-of-Findings.pdf
PPT
chapter 5: system unit computing essentials
PPTX
IoT Lecture IoT Lecture IoT Lecture IoT Lecture
How Technology Shapes Our Information Age
Digital Project Mastery using Autodesk Docs Workshops
Tailieuhoctiengnhat.com__(N5) 1021 từ vựng tổng hợp.pdf
Technical SEO Explained: How To Make Your Website Search-Friendly
B2B Marketing mba class material for study
c_languagew_structure_and_functions.pptx
Audio to Video AI Technology Revolutiona
北安普顿大学毕业证UoN成绩单GPA修改北安普顿大学i20学历认证文凭
Chapter 1_Overview hhhhhhhhhhhhhhhhhhhhhhhhhh
Introduction: Living in the IT ERA.pptx
AGENT SLOT TERPERCAYA INDONESIA – MAIN MUDAH, WD CEPAT, HANYA DI KANCA4D
Information Technology practical assignment
FreePBX_Project_Presentation_With_Gantt.pptx
Data Flows presentation hubspot crm.pptx
Expect The Impossiblesssssssssssssss.ppt
Comparison of 2 Population Kuch toh bhadwa chodi karwa raha
IOT LECTURE IOT LECTURE IOT LECTURE IOT LECTURE
Lesson.-Reporting-and-Sharing-of-Findings.pdf
chapter 5: system unit computing essentials
IoT Lecture IoT Lecture IoT Lecture IoT Lecture

Introduction to JavaScript

  • 1. Z Week 11: Introduction to JavaScript Subject Code: COMP121 By: Marlon Jamera Email: [email protected]
  • 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

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