JavaScript can be embedded in an HTML document in two ways:
As statements and functions using the SCRIPT tag.
As event handlers using HTML tags.
The SCRIPT tag
A script embedded in HTML with the SCRIPT tag uses the format:
The optional LANGUAGE attribute specifies the scripting language as
follows:
The HMTL tag, <SCRIPT>, and its closing counterpart, </SCRIPT>
can enclose any number of JavaScript statements in a document.
JavaScript is case sensitive.
Example 1: a simple script.
That's all, folks.
Example 1 page display.
Hello net. That's all folks.
Code Hiding
Scripts can be placed inside comment fields to ensure that your
JavaScript code is not displayed by old browsers that do not
recognize JavaScript. The entire script is encased by HTML comment
tags:
Defining and Calling Functions
Scripts placed within SCRIPT tags are evaluated after the page loads.
Functions are stored, but not executed. Functions are executed by
events in the page.
It's important to understand the difference between defining a
function and calling the function. Defining the function simply
names the function and specifies what to do when the function is
called. Calling the function actually performs the specified actions
with the indicated parameters.
Example 2: a script with a function and comments.
All done.
Example 2 page display.
All done.
The HEAD tag
Generally, you should define the functions for a page in the HEAD
portion of a document. Since the HEAD is loaded first, this practice
guarantees that functions are loaded before the user has a chance to
do anything that might call a function.
Example 3: a script with two functions.
Thanks.
Example 3 results.
Thanks.
Quotes
Use single quotes (') to delimit string literals so that scripts can
distinguish the literal from attribute values enclosed in double
quotes. In the previous example, function bar contains the literal
'left' within a double-quoted attribute value. Here's another
example: