|
Const Statement |
Top Previous Next |
Function: |
Declares constants for use in place of literal values. |
Syntax: |
const name = value |
Scope: |
Global, HTML and local |
See Also: |
Part |
Description |
name |
The name of the constant, later used to refer to this constant in code. |
value |
The value for the constant; this can be an expression. |
Details
This statement defines an identifier, and binds a constant value to it. During compilation, when the compiler finds an identifier, it substitutes the identifier with the value given for the constant.
When defining a constant, you can use any valid constant expression; this can be another constant, a string, or a mathematical expression. Of course, constant expressions cannot include variables, functions, or other elements of code which are not constant (and, hence, cannot be resolved during compilation).
Global constants are usually declared in the header file.
Examples
const foo = "abc" + "fddf" const bar = 123 + 56 * 56 const foobar = "dfdffgfg"
|