JavaScript Statements
JavaScript also includes built-in statements, which allow you to do things like set up loops in your program. One of the most important statements is the function statement, which is the keyword you will use to create JavaScript functions - a set of procedures that performs a specific task. Once defined, a function can be called anywhere within a script. Most of the remaining JavaScript statements are used to build branches or loops in your JavaScript programs. Some of the most commonly used statements include
* var
the var statement declares a variable name with its given value, for instance, var a = 1.
* if ... else
This is a conditional statement that executes one set of statements if a condition is true and a second set of statements if a condition is false.
var x=0
if (x==1){
document.write("x=1") }
else {
document.write("x does not equal 1") }
The output for this script would be
x does not equal 1
* for
The for statement is used to build loops. A typical application of a for loop is a counter, like:
for (var i = 0; i < 10; I++){
document.write(i) }
The output for this script would be
0123456789