Console Learner — An interactive JavaScript course.
2.4 Statements
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.
>>>
var a = 1;
var 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.
>>>
The console allows you to interact with the course material and
examples. Use the following keys:
<Enter> — Execute the code
<Shift + Enter> — Add
line break
<Arrow-Up> — Previous
command in history
<Arrow-Down> — Next command in history
A special logging function is also available:
print(value) — Prints a value to
the console.
print(value, true) — Prints a debug
version of a value.
Need more magic? Check out the other
developer tools
on this site.