Lesson 15 Introduction To JavaScripts
Lesson 15 Introduction To JavaScripts
Lesson 15 Introduction To JavaScripts
Objectives:
learn about JavaScript
o <script> tag
o JS Output
o JavaScript Statements
Outcomes:
Knowledge on the basic JS concepts
Notes:
JavaScript in <head>
In this example, a JavaScript function is placed in
the <head> section of an HTML page.
The function is invoked (called) when a button is clicked:
JavaScript in <body>
In this example, a JavaScript function is placed in
the <body> section of an HTML page.
The function is invoked (called) when a button is clicked:
External JavaScript
Scripts can also be placed in external files:
External References
An external script can be referenced in 3 different ways:
With a full URL (a full web address)
With a file path (like /js/)
Without any path
This example uses a full URL to link to myScript.js:
<script src="https://www.Youtube.com/js/
myScript.js"></script>
JavaScript Output
JavaScript Display Possibilities
JavaScript can "display" data in different ways:
Writing into an HTML element, using innerHTML.
Writing into the HTML output using document.write().
Writing into an alert box, using window.alert().
Writing into the browser console, using console.log().
________________________________________________________________
Using innerHTML
To access an HTML element, JavaScript can use
the document.getElementById(id) method.
The id attribute defines the HTML element.
The innerHTML property defines the HTML content:
Using document.write()
For testing purposes, it is convenient to use document.write():
Using document.write() after an HTML document is loaded, will delete all
existing HTML:
JavaScript Print
JavaScript does not have any print object or print methods.
You cannot access output devices from JavaScript.
The only exception is that you can call
the window.print() method in the browser to print the content
of the current window.
JavaScript Statements
JavaScript Programs
A computer program is a list of "instructions" to be
"executed" by a computer.
In a programming language, these programming instructions
are called statements.
A JavaScript program is a list of programming statements.
In HTML, JavaScript programs are executed by the web browser.
JavaScript Statements
JavaScript statements are composed of:
Values, Operators, Expressions, Keywords, and Comments.
This statement tells the browser to write "Hello Dolly." inside an
HTML element with id="demo":
--------------------------------------END OF
LESSON----------------------------------------------