Perceptions of HTML and JavaScript

HTML

The hypertext markup language uses tags (or commands) saved in a text document (except with the extension .htm or .html) to tell an Internet browser what to do. HTML is, however, limited in that it requires a browser to view the end product. Without the browser, an HTML document, when opened in a text editor such as notepad, is a series of symbols and words. The programming world therefore does not officially recognize HTML as a programming language.

JavaScript

JavaScript uses objects (or preprogrammed parts) found in a browser or created by a programmer to extend the Internet experience. It may be argued that JavaScript is less of a programming language than HTML because JavaScripts are usually invoked from within HTML code. However, Netscape does use a JavaScript compiler to interpret and assemble embedded code. JavaScripts may also be stored in independent containers, but this is beyond the scope of this class.

<html>

<head>

<title>An example script</title>

<script language=javascript>

/* Use these symbols to add comments */

<!--

//-->

</script>

</head>

</html>

Obviously, this one isn't very useful because it doesn't do anything except show you the tags to include. (-:

Notice the <!--and //--> symbols. These are used to hide script code from browsers that cannot recognize JavaScript.

An Introduction to JavaScript

JavaScripts are embedded (or placed) within html documents... at least for the purposes of this class. It is assumed that you have at least partially mastered HTML so that the subsequent discussion of tags will be intuitive. Scripts should be placed in the <head> section of your html along with the title and/or any metatags that you may define so that the script loads first. You may place a script anywhere in your HTML but you may experience problems if your script isn't loaded prior to a function call from an HTML statement. An example of a simple script:

A simple JavaScript may look like:

<html>

<head>

<title>A simple JavaScript</title>

<script language=javascript>

//A simple script

<! - -

document.write("Hello, World!")

//- - >

</script>

</head>

<body>

</body>

</html>

One may argue that a better way to write the same lines of code would be*:

<html>

<head>

<title>A simple sentence</title>

</head>

<body>

Hello, World!

</body>

</html>

*However, if you wanted to store multiple lines of text and possibly choose the order that the sentences were presented, HTML would stall. JavaScript would allow you to use an object known as an array to store the sentences and present them in the desired order.

Alert Box Simple script that does something.

<html>

<head>

<title>An example script</title>

<script language=javascript>

/* Use these symbols to add comments */

<!--

alert("My first cool script!")

//-->

</script>

</head>

</html>

This script makes an simple and annoying alert box appear with the message "My first cool script".
Home