Sams Teach Yourself JavaScript in 24 Hours

Sams Teach Yourself JavaScript in 24 Hours

By Michael Moncur

Learning Web Scripting Basics

In the world of science fiction movies (and many other movies that have no excuse), computers are often seen obeying commands in English. While this may indeed happen in the near future, computers currently find it easier to understand languages like BASIC, C, and Java.

If you know how to use HTML to create a Web document, you've already worked with one computer language. You use HTML tags to describe how you want your document formatted, and the browser obeys your commands and shows the formatted document to the user.

Since HTML is a simple text markup language, it can't respond to the user, make decisions, or automate repetitive tasks. Interactive tasks like these require a more complex language: a programming language, or a scripting language.

While many programming languages are complex, scripting languages are generally simple. They have a simple syntax, can perform tasks with a minimum of commands, and are easy to learn. Web scripting languages allow you to combine scripting with HTML to create interactive Web pages.

Scripts and Programs

A movie or play follows a script—a list of actions (or lines) for the actors to perform. A Web script provides the same type of instructions for the browser. A script in JavaScript can range from a single line to a full-scale application. (In either case, JavaScript scripts almost always run within a browser.)

Some programming languages must be compiled, or translated into machine code, before they can be executed. JavaScript, on the other hand, is an interpreted language: The browser executes each line of script as it comes to it.

There is one main advantage to interpreted languages: writing or changing a script is very simple. Changing a JavaScript script is as easy as changing a typical HTML document, and the change is enacted as soon as you reload the document in the browser.

Introducing JavaScript

JavaScript was developed by Netscape Communications Corporation, the makers of the popular Netscape Web browser. JavaScript was the first Web scripting language to be introduced, and it is still by far the most popular.

JavaScript is almost as easy to learn as HTML, and it can be included directly in HTML documents. Here are a few of the things you can do with JavaScript:

You can do all this and more with JavaScript, including creating entire applications. We'll explore the uses of JavaScript throughout this book.

Share ThisShare This

Informit Network