Getting Started: Setting Up your code.

Where do your JavaScript codes go? Well, basically anywhere inside the <html> tags of your page. The beginning of your code begins with <script type="text/javascript"> and ends with </script>

<head><title>This is an example page</title></head>
Welcome to the JavaScript course!
<script type="text/javascript">
document.write("Hi there. This text is written using JavaScript!")

Output: Hi there. This text is written using JavaScript!

As you can see, we began our script with the tag <script language="type/javascript"> The part in red is purely optional, as the browser by default assumes a <script> tag to be JavaScript, though you should include it nevertheless for validation reasons. The second and next to last lines of the above example are <!-- and //-->, which are HTML comment tags tailored for JavaScript. It is recommended you include them to hide your code against very old browsers that don't support JavaScript. If you don't include them and someone is using such a browser, the browser will just "dump" all your code as text onto the screen, in other words, not a pretty sight! The only "functional part" of this script is the document.write(".......") part. It basically writes to the page whatever you put inside the quotation marks. Don't worry so much about why this is so yet, we will discuss this in detail later. We end this entire code with </script> This terminates your script, and brings you back to html.

Like html, you can insert comments in your JavaScript codes. JavaScript comments are different from HTML comments, with the later commenting out certain lines within your script so they don't get interpreted. The syntax for JavaScript comments are:

//comment here

for single-lined comments, or

comment here

for multiple ones.

For example:

<script language="JavaScript">
//this script does nothing and is useless!
Hay, don't involve me
in this!

Ok, we are now ready to proceed to some real programming!

JavaScript, like many programming languages, relies on objects, functions, and event handlers to create workable programs.   If you know absolutely nothing about these technical terms and how to use them, don't worry. By the time we're through with this tutorial, you will.