Home

The Basics of JavaScript Statements

|
Updated:  
2016-03-26 07:26:28
|
JavaScript Essentials For Dummies
Explore Book
Buy On Amazon

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.

About This Article

This article is from the book: 

About the book author:

Chris Minnick is an accomplished author, teacher, and programmer. Minnick authored or co-authored over 20 books, including titles in the For Dummies series. He has developed video courses for top online training platforms and he teaches programming and machine learning to professional developers at some of the largest global companies.

Eva Holland is an experienced web developer, tech trainer, and coauthor of Coding with JavaScript For Dummies. She is a co-founder of WatzThis?, a company focused on training and course development.