javascript interactive

JavaScript Interactive — a console crash course


2.2 Statements

Warning: Your browser may be outdated or unsupported.

The JavaScript console is known to display some of the examples incorrectly in Internet Explorer 8 or older.
  • An expression is a calculation or operation that results in a value. Except for variable declarations, everything until now have been expressions.
  • A statement is any construct permitted by the language, including an expression. A JavaScript program consists of a sequence of statements, all separated from each other.
>>>
a = 1;
b = a + 1;

  
A ; character is used to separate statements. Several statements can be placed on a single line, although it is commonly avoided.
>>>
{
    var a = 1;
    a += 2;
}

  
The { and } characters are (also) used to group several statements. This is sometimes called a block.
>>>
a = 1, b = a + 1
2
The , operator in expressions is similar to the ; statement separator. It evaluates both expressions, but will only return the second one. Compare with the boolean operators:
  • A && B — If A is true, evaluate B.
  • A || B — If A is false, evaluate B.
  • A , B — Always evaluate A and B.
>>>

Index 1 2 3 4 5 6 7 8