Javascript Programming 101

The third line is the closing tag.

Now, we scroll down the page a bit. Inside the BODY tag, we see this:

<script language="JavaScript">document.write(message);</script>

As you can see, the standard opening and closing JavaScript tags are present. But what's that in between them? It's this (look at it for awhile and try to guess how it works…then read on!):

document.write(message);

This is quite simple really. What makes sense right off the bat?

The beginning is a bit trickier: JavaScript uses something called the Document Object Model - or DOM for short. Think of the DOM as different things that have different properties. For example: your computer has an operating system. Your operating system has a program called a browser, most likely. Your browser has different things about it that make up how it looks - the color of it's scrollbar, its name, or the little pictures on it's Stop/Refresh/Forward/Back buttons.

JavaScript is like this. Another word for "a webpage" is, basically, "a document." As such, we're calling on the document property here. But, of course, we need to be more specific than that. We want to print out the value of the "message" variable - so, in this case, we call on the document property, and add a ".write" - a period, then the word "write" - to it.

Why? Because "write" is a sub-property of document - it's one of the things the document can do. It can write. It can write text to a webpage. There are many properties within the document object. One of the most useful is the one that allows us to manipulate forms, which we will go into in the next installment of this tutorial. For now, just think of the DOM through the analogy used above.

If you use the entire, original block of code on a webpage, you should simply see the text "Welcome to this page!" - and nothing else. Congratulations, you've written your first JavaScript, and odds are, you probably understand how it works. Bonus points if you feel you understand the DOM - a lot of people struggle (myself included) with that aspect of JavaScript.