SPS Home > Dgreath > JavaScript > Expressions |
JAVASCRIPT EXPRESSIONS |
---|
The following information describes JavaScript expressions. |
JAVASCRIPT EXECUTION BLOCKS(BLOCK)
|
---|
JavaScript statements consist of one, two, or possibly three properly formed expressions. An expression consists of an operator and one or two operands and perform either assignment, comparison, or computation tasks. Operands can be either literal values or variables. Literals and variable values can be Boolean, numerical, or string types. Boolean types have truth values of 'true' or 'false'. Numerical types can be positive, negative, or zero either real or integer. String types are essentially an array of displayable characters capable of being displayed as a group or parsed out individually by the use of String functions. Since JavaScript is not a typed language, it is imperative to ensure that appropriate operands are used in each expression. So, for example, a number can be added to a number but if the number is quoted, it becomes a string. Since a string cannot be added to a number, the expression will fail. However, a number can be compared to a string representation of the number. One of the most common problems in JavaScript is type mismatching. An expression can also be a complete statement as well thus providing the capability to nest statements within statements. Assignment Expressions: Numerical Expressions: Statement Expressions: |
JAVASCRIPT CONDITION BLOCKS(CONDITION)
|
---|
Conditional Expressions: |
JAVASCRIPT LABEL BLOCKS[label]
|
---|
JavaScript allows statements to be labeled as targets for break and continue
statements used in for and while loops. To label a statement,
precede the statement by the label and a colon (i.e. begin:somestatement ).
The colon (:) operator delimits the label from the statement.
Labels must conform to the general rules for JavaScript identifiers.
|
JAVASCRIPT SCOPE | ||||||
---|---|---|---|---|---|---|
Scope: The scope of a JavaScript expression is delimited by the opening curly brace ( " { " )and closing curly brace ( "} " ). Statements
within a scope are executed as block. The semi-colon ( "; " ) character
is used as a separator between statements coded within a block regardless of
whether the block is written horizontally or vertically (see below). Variables
declared with a var statement are private to the containing scope and can only
be referenced within that scope, whereas those declared without the var
statement are public with respect to the scope and can be reference both within
and without the scope.The following examples illustrate the proper stylistic use of scope in both horizontal or vertical formatted code. Note that when whitespace is ignored, either method presents the identical code to the compiler/assembler.
|