JavaScript
JavaScript is a programming language.
JavaScript programs run inside the browser, tell the browser what to do
Internal (embedded) JavaScript
One or more lines of JavaScript inside a script element
Internal JavaScript runs when the web browser (which reads the source code from top to bottom) gets to the script tag
Use your browser’s “View Source” command to see (and copy) the JavaScript source code
Source code looks something like this:
Inline JavaScript
One or more lines of JavaScript inside a tag
This example demonstrates the alert statement
Source code looks something like this:
External JavaScript files
An external JavaScript file is a text file that has the .js file extension, containing JavaScript code
External files are useful because multiple pages can share a single JavaScript file
Sometimes known as global code, shared code, etc.
The above examples demonstrate the concept of variables
External style sheet located here:
http://67.20.67.178/dw/wpdw/wp-content/themes/simplr-kgj/scripts/intro.js
Source code (on this page, to attach the external JavaScript file) looks something like this:
JavaScript functions
To keep the browser from executing a script when the page loads, you can put your script into a function
A function contains code that will be executed by an event or by a call to the function
Functions look like this:
function functionName (arguments) {
// JavaScript statements go here
}
You may call a function from anywhere within a page, or from an external JavaScript file
Functions can be defined both in the and in the section of a document. However, to assure that a function is read/loaded by the browser before it is called, it could be wise to put functions in the section.
Function can use arguments: one or more values that the function needs to complete its tasks, which might change depending on which element is calling the function and for what purpose
— Arguments are the part of the function that go inside the parenthesis ()
— Arguments are optional
— If a function does not use arguments, use the parentheses with nothing inside
Functions are useful for writing re-usable code
See JavaScript Functions at w3schools.org