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.

Categories: Basics

0 thoughts on “JavaScript Basics Part 1: Statements”

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Basics

JavaScript Basics Part 7: Loops

Loops are used to execute the same statement of code a set number of times, which can be hardcoded or based on variable. Loops are very common within programming, as they solve the problem of Read more…

Basics

JavaScript Basics Part 6: Conditionals

Logic is a part of our everyday lives – it’s a very familiar concept, therefore one of the easiest to understand. We are faced with questions all the time, with the “If” question being the Read more…

Basics

JavaScript Basics Part 5: Arrays

An array is a variable which can store many values inside it. A variable can only store one value. Those values can be accessed at any time using the array’s index. The values stored within Read more…