The Basics of JavaScript Statements

By Chris Minnick, Eva Holland

In English, people talk in sentences. In JavaScript, a single instruction to the computer is called a statement. Like a sentence, statements are made up of different parts and have certain rules that they must follow in order to be understood.

Following shows an example of a statement.

alert("Coding is fun!");

This statement causes a web browser to open up a popup alert window with the sentence “Coding is fun!” If you type this statement into the JavaScript Console in Chrome, you’ll see something like what’s shown here.

The output of a JavaScript alert statement.

The output of a JavaScript alert statement.

Notice that the statement contains a keyword, some symbols (parentheses and quotes), and some text (Coding is fun!), and it ends with a semicolon.

Just as an infinite number of sentences can be written using English, an infinite number of statements can be written with JavaScript.

The word alert is an example of a JavaScript keyword. Many JavaScript statements begin with keywords, but not all of them do.

The semicolon is what separates one statement from another, just as a period separates one sentence from another. Every statement should end with a semicolon.