background
|
|
Linux
Linux Support
A small area on the internet for Linux Support.
More icon

News
All in one Place
All of your regular news in one place.
More icon
|
|
Up Image
Navigation
Search this Site
Enter your search terms

Site Breadcrumb - You are here
|
Thau's JavaScript Tutorial
Lesson 1

by Thau!

Page 3 — Down to Business

Congratulations!

You've just seen an example of JavaScript in action! If you view source, you'll see something that looks like this:

<HTML>
<head>
<title>
Thau's JavaScript Tutorial
</title>

<script language="JavaScript">

// put up an alert box, to show how they work

alert("Soon, I will rebuild my browser!");

</script>

</head>

Here are the key things to notice:

JavaScript usually goes between the </title> tag and the </head> tag.
Like HTML, JavaScript is just text that can be typed into a word processor. It goes right into the HTML that describes your page. (Although I've only shown JavaScript in the header of the HTML page, you can also put JavaScript in the body. You'll see an example of this in the next lesson.)

The beginning of a bit of JavaScript begins with <script language="JavaScript">
Right now, you don't really have to put the language="JavaScript" element in there because JavaScript is the default script language for all browsers. However, this could change, so it's a good idea to include the language element.

Everything between // and the end of a line is a comment and will be ignored.
Comment, comment, comment! A basic rule of good programming style is that you should always think about the next person who has to look at your script. It might be a friend, a co-worker, an employer, or it could be you in three months. The easiest way to make sure you'll understand your own script in three months is to comment freely and often. If you want to comment a huge block of text, you can put it between /* and */ like this:

    /* this is
    a huge block
    of text that I've
    commented out */

alert("Soon, I will rebuild my browser!"); calls up a simple dialog box with the words "Soon, I will rebuild my browser!" inside.
Here's your first piece of JavaScript: the alert method. You'll learn more about how this line works in the next lesson. For now, you just need to know that you should end it with a semicolon, and put the text you want in the alert box between quotes.

JavaScripts end with the </script> tag.
No rocket science here. Easy as HTML.
Simple, right? Well ... actually, there's one complication.

next page»