JavaScript Basics Part 1: Statements

The basic components of JavaScript programs are statements, variables, and types of data.

A JavaScript statement is the most basic piece of JavaScript – which will represent a single action or step in the script that you are building. Many statements will represent a script, and they will always run from top to bottom, similar to how you read a book.

In the following example, there are two statements. The first will write the line ‘hello world, this is the edge’ to the document. The second statement will show a JavaScript alert to the user that says ‘say hello to the world’. You will notice at the end of each line is a semi-colon. It is used to tell the JavaScript interpreter that this statement has ended, and to move onto the next one. Without this semi-colon, the program will get stuck at whichever line is missing the semi-colon.

document.write(‘hello world, this is the edge’);
alert(‘say hello to the world’);

It is very common to see statements as part of a function in between two curly brackets.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: