Specifications

Identifiers, variables and constants
JavaScript identifiers match the regexp pattern [_A-Za-z][_A-Za-z0-9]*. Identifiers are
used for variables, constants, class names, function names and labels. JavaScript reserves some
words which are valid identifiers for its own use. See declarations for the complete list.
Variables are declared using the var keyword:
var a;
// undefinedvar c = "foliage";
// the string "foliage"x = 1;
// global variable
If a variable is assigned without being declared, it is automatically declared as a global variable.
Using global variables can make your code difficult to debug and maintain and is not
recommended.
Constants are declared using the "const" keyword:
const x = "Willow";
const y = 42;
Constants must be defined at the point of declaration, because they cannot be changed later.
If an attempt is made to assign to a constant, the JavaScript interpreter will issue an error message
and stop.
Constants are public globals if they are declared outside of any enclosing braces. When declared
within the scope of some braces, (example: within an "if" statement) their scope is local to the
enclosing block.
Classes
JavaScript is a fully object oriented language. Classes can be defined using the class keyword as
shown in the example below.
class Circle
{
var m_x;
var m_y;
var m_r;
function Circle( posx, posy, radius )
{
m_x = posx;
m_y = posy;
m_r = radius;
}
function setX( posx )
{
m_x = posy;
}
function setY( posy )
{
m_y = posy;
}
function setR( radius )
{
m_r = radius;
}
function x()
{
return m_x;
}
369
Enfocus Switch 10