O'Reilly logo

JavaScript® 24-Hour Trainer by Jeremy McPeak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Variables and JavaScript Syntax

In the midst of teaching you how and where you add script to your pages, the previous lesson introduced the following simple script:

function inlineScript() {
    var message = "Hello, World!";
    alert(message);
}

inlineScript();

To fully understand what this code does, it's important to know the basics of the JavaScript language. The core of any language is its syntax — a set of rules that dictate how certain pieces of the language fit together. Think of a spoken language and how difficult it would be to communicate with others if that language did not have a set of rules that defined how words are arranged into complete and understandable sentences. The same is applicable to programming languages. In the case of JavaScript, the browser wouldn't know what to do with your code if it weren't for the rules set forth by the language specifications. Syntax defines how very small pieces of code fit together in order to perform some kind of work.

This lesson focuses on the syntax of one line of code in the listing at the top of the page — the variable declaration:

var message = "Hello, World!";

In this lesson, you learn about variables and the syntax required to make them.

VARIABLES

Developers write programs to make working with data easier. Large amounts of data are typically stored outside the program, via the file system or a database, but many times that data is brought into the application and stored in the computer's memory. Because of this, all programming ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required