A computer program is a list of “instructions” to be “executed” by a computer.
In a programming language, these programming instructions are known as statements.
The first thing we’ll study is the building blocks of code.
Values, Operators, Expressions, Keywords, and Comments.
We’ve already seen a statement,
alert('Hello, world!'), which shows the message “Hello, world!”.
We can have as many statements in our code as we want.
It is terminated with a semicolon.
Wrong Method: Here “Hello World” are given into two statements alert:
Correct Usage: Usually, statements are placed on separate next lines to make the code more easy readable:
The following lines are equivalent:
var person = "Hege"; var person="Hege";
A good practice is to put spaces around operators ( = + – * / ):
var x = y + z;
|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 true|
|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|