A statement is an instruction that makes a program perform some action.
Statements are separated either with a line break or a semicolon (;)
More than one statement may occur on a single line of text, provided that they are separated by semicolons.
A semicolon is not needed between statements that occur on separate lines, however it is recommended to use it anyway in case the line breaks are removed later.
A statement may be written over multiple lines of text. However, do not use line break inside string constants as this will give a script error. If you need a line break inside a string, you must use \n(go to Characters and Strings for more information). Also, postfix increment and decrement operators must appear on the same line as their argument (e.g. i++ and i--, (go to Arithmetic Operators for more information), continue and break keywords must appear on the same line as their label (go to break Statement for more information), and return must appear on the same line as its expression (go to return Statement for more information).
A group of statements surrounded by curly brackets ({}) is called a block. Statements within a block can generally be treated as a single statement. They are used to group a set of statements inside branches of a condition, or inside loops and functions.
Declarations
We have used the following code snippets to declare variables and constants.
JScript example:
var variableName {: type} = expression;const constantName {: type} = expression;JavaScript example:
const constantName = expression;
var variableName = expression;
Using the following example:
JScript example:
var x : int = 12;
JavaScript example:
JavaScript Example
var x = 12;
This both identifies the variable x and causes it to be initialized to the value of 12. In the JScript example, this will also cause the variable to be declared explicitly as an int.
In JScript, the type declaration is optional for both constant and variable declaration. So, the following is valid in JScript:
JScript example:
var x = 12;
In both JavaScript and JScript, variables do not necessarily need to be initialized to any value. Constants, however, do need to be initialized.
JScript example:
var x;Fine
var x: int;Fine
const x = 42;Fine
const x : int = 42;Fine
const x;Problematic
JavaScript example:
var x;Fine
const x = 42;Fine
const x;Problematic