This section provides a quick description of different types of statements and a tutorial example on how to write expression and other statements.
What is a statement?
A statement is a basic execution unit in JavaScript.
Several notes about JavaScript statements:
A statement must end with semicolon (;).
Line breaks do not end statements. In other words, a single statement can be written in multiple lines,
and multiple statements can be written in a single line.
A statement may be consist of a very simple expression, like a single literal;
or a complex expression with assignment and or comma operators.
Most statements have statement key words, like "var", "if", "while", "break", etc.
Multiple statements may be grouped together to form a statement block in the format of {s1; s2; ...; }.
Comments enclosed in "/* ... */" or "// ... (end of line)" can be inserted anywhere inside a statement.
Here is a JavaScript tutorial example that shows you different types of statements:
<html>
<!-- Statements.html
Copyright (c) 2008 by Dr. Herong Yang, http://www.herongyang.com/
-->
<head><title>Statements</title></head>
<body>
<pre>
<script type="text/javascript">
var x,y,z; // A "var" statement
x=1, y=4, z=9; /* An expression statement
with 3 comma operators and 3 assignment operators.
The result this expression is 9.*/
x*x; y*y; z*z; // 3 statements in 1 line
{ // a statement block
x *= x;
y *= y;
z *= z;
}
if (true) // A "if" statement
document.write("7 statements in total.");
</script>
</pre>
</body>
</html>