JavaScript Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 2.00

Walking through the First JavaScript

This section provides a walkthrough of the first JavaScript - 'Hello World!'.

Now let's walkthrough our first JavaScript, "Hello World!", provided in the previous section:

1 <html>
2 <head><title>Hello World!</title></head>
3 <body>
4 <script type="text/javascript">
5    document.write('Hello World!');
6 </script>
7 </body>
8 </html>

The first 3 lines are normal HTML tags.

Line 4 has a special HTML tag <script> that starts a section of JavaScript code. Notice that the type="text/javascript" attribute indicates that the script contained in the tag is a JavaScript.

Line 5 is the only JavaScript statement in this HTML document, which calls the write() function of the built-in object "document". This call will output the string "Hello World!" into the HTML document.

Line 6 ends the JavaScript code.

When the Web browser processes this HTML document, it will interpret all JavaScript statements within the <script>.

Sections in This Chapter

What Is JavaScript?

First JavaScript - "Hello World!"

Walking through the First JavaScript

The document.write() Method

Dr. Herong Yang, updated in 2008
Walking through the First JavaScript