JavaScript Basics Part 1: Statements

0

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.

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

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

LEAVE A REPLY