x = 5; // Statement 2
y = 6; // Statement 3
z = x + y; // Statement 4
is a list of “instructions” to be
“executed” by a computer.
In a programming language, these programming instructions are called
is a list of programming
Values, Operators, Expressions, Keywords,
This statement tells the browser to write “Hello Dolly.”
inside an HTML element with id=”demo”:
The statements are executed, one by one, in the
same order as they are written.
Add a semicolon at the end of each executable statement:
a = 5;
// Assign the value 5 to a
b = 6; // Assign the
value 6 to b
c = a + b; // Assign the sum of a and b to c
When separated by semicolons, multiple statements on one line are allowed:
On the web, you might see examples without semicolons.
Ending statements with semicolon is not required, but highly recommended.
The following lines are equivalent:
A good practice is to put spaces around operators ( = + – * / ):
For best readability, programmers often like to avoid code lines longer than 80
it is after an operator:
The purpose of code blocks is to define statements to be executed together.
One place you will find statements grouped together in blocks, is in
document.getElementById(“demo1”).innerHTML = “Hello Dolly!”;
document.getElementById(“demo2”).innerHTML = “How are you?”;
In this tutorial we use 2 spaces of indentation for code blocks.
You will learn more about functions later in this tutorial.
Visit our Reserved Words reference to view a full list of
Here is a list of some of the keywords you will learn about in
|break||Terminates a switch or a loop|
|continue||Jumps out of a loop and starts at the top|
|do … while||
Executes a block of statements, and repeats the block, while a condition is
|for||Marks a block of statements to be executed, as long as a condition is true|
|function||Declares a function|
|if … else||Marks a block of statements to be executed, depending on a condition|
|return||Exits a function|
|switch||Marks a block of statements to be executed, depending on different cases|
|try … catch||Implements error handling to a block of statements|
|var||Declares a variable|