Identifiers start with an alphabetic character or '_' or '$' or '@', followed by any number of alphabetic characters, '_', '$', '@' or digits ([0-9]).
"Foo", "foo" and "FOO" are three distinct and valid identifiers.
Here is a full list of keywords used by the language. These cannot be used as identifiers:
function, var, if, else, while, return, for, break, continue, do, switch, case, default, null, super, new, try, catch, finally, throw, typeof, instanceof, in, property, const, get, set, include, like, yield, type, class, namespace, assert, debug otherwise
Operators used by the language:
= ! ~ ^ * / % + - & | = > && || ++ -- += -= *= /= %= &= |= ^= >= .. === !== >> >>= ~/ ~% /~ %~
Special symbols are:
[ ] { } # " ' `
A multi line comment is text enclosed in /*
and */
brackets.
A single line comment starts with //
and spans everything until the end of that line.
Pattern | Example | Description |
-?[1-9][0-9]* |
34 | Decimal number |
-?0[0-9]* |
0336 | Octal number |
-?0[xX][0-9a-fA-F]+ |
0x3d | Hexadecimal number |
'.' |
'A' | Character code (integer) |
Pattern | Example | Description |
-?[0-9]*\.[0-9]+ |
3.1415926 | 3.1415926 |
-?[0-9]+[eE]-?[0-9]+ |
-5e3 | -5000.0 |
-?[0-9]*\.[0-9]+[eE]-?[0-9]+ |
.22e-2 | 0.0022 |
String literals are sequences of characters, enclosed by double quotes - "
, or back ticks (grave accent, character with code 0x60) - `
"Hello world"
and `Hello world`
are valid string literals. The escapement symbol in string literals is the back slash - \
.
Escapement rules:
Sequence | Character |
\b |
backspace character |
\t |
tab character |
\n |
newline character |
\f |
form feed character |
\r |
carriage return character |
\" |
double quote character |
\\ |
backslash character |
\` |
backtick character |
\[0-7]{1,3} |
\116 - octal character literal |
\x[0-9a-fA-F]{1,2} |
\4e - hexadecimal character code |
\u[0-9a-fA-F]{4} |
\u004E - unicode character code |
Two or more string literals, separated by whitespaces or EOL characters, constitute a single string literal. Thus, the following two strings:
var str1 = "The quick brown " "fox jumps over " "the lazy dog"; var str2 = "The quick brown fox jumps over the lazy dog";
are equivalent.
Symbol literals are sequences of valid characters starting from '#
' symbol.
Valid characters here are: lower- and upper-case letters, digits, '_' (underscore sign), '$
' (dollar sign), '@
' (at-sign) and '-
' (minus sign).
Note that symbols may contain minus sign. This is made intentionally to support CSS names. Examples of valid symbol literals:
var symFontFace = #font-face; var symBorder = #border;
Literal | Description |
undefined |
implicit no-value, this value is returned by an attempt to read a non-existing property of an object. typeof undefined is #symbol |
null |
explicit no-value. typeof null is #object |
true |
true value in logical operations. typeof true is #boolean |
false |
false value in logical operations. typeof false is #boolean |
Array literals allow to define (construct) arrays inline. The array literal is a list of expressions-initializers, separated by comma ,
and enclosed in [
and ]
brackets (square brackets):
var a = [ 1, 2, 3, "four", 5 ];
In the statement above, variable a gets the reference to the newly defined array with five elements.
Any ,
(comma) appearing between the last element, and the ]
(closing square bracket) is ignored. Therefore, this is also a valid array declaration:
var a = [ 1, 2, 3, "four", 5, ];
Array literals may contain so called spread expressions .. <iterable>
where <iterable>
is either an array, tuple or instance of a generator. Spreads allow array literal to be composed from other arrays and generated sequences. So this produces true
:
var a1 = [0,1,2]; var a2 = [..a1, 3, 4]; a2 == [0, 1, 2, 3, 4];
The kind-of-formal definition of the array literal:
[
( <rs-expr>
,
)* ]
Where <rs-expr> is the so-called right side expression - the expression that can appear on the right side of the =
(assignment) operator.
Object literals allow to define (construct) objects inline. The object literal is a list of key-value pairs separated by ,
(comma) or ;
(semicolon), and enclosed in {
and }
brackets (curled brackets). Each key-value pair consists of the key expression-initializer, and the value expression-initializer, separated by :
(colon).
var obj = { one: 1, two: 2, three: "three", four:4 };
If the key is presented as a name token, it is interpreted as a symbol name. Thus, the following statement:
var obj = { #one: 1, #two: 2, #three: "three", #four:4 };
is a precise equivalent of the statement above.
If the first token after the opening {
bracket is :
(semicolon), the expression that follows is treated as a class name. This allows to define objects of user-defined classes in literal form:
var myObj = {:MyClass one:1, two:2, three: "three", four:4 };
The formal definition of the object literal:
{
[ :
<class-name>
] ( <rs-expr>
:
<rs-expr>
[ ,;
] )* ( <rs-expr>
:
<rs-expr>
)? }
The RegExp literal is a sequence of regular expression components, enclosed by /
(forward slash) :
var re = /^[ \t]*$/ ; // RE expression for matching blank lines.
The kind-of-formal definition of RE literal:
/
<re-expression> /
[i
][g
]
where i means case-insensitive match, and g enables "global" matching. When using the RegExp.exec() method, specify this modifier to return all matches, rather than the first one.
Tuple literals allow to define (construct) tuples inline. The tuple literal is a [
(opening square bracket) followed by symbol - tag of the tuple, then :
symbol and the list of expressions-initializers, separated by comma ,
closed by ]
bracket (closing square bracket):
var tup = [tupletag: 1, 2, 3, "four", 5 ];
In the statement above, variable tup gets the reference to the newly defined 5-tuple - tuple that has five elements. tup.tag
property will have value of #tupletag
.
Any ,
(comma) appearing between the last element, and the ]
(closing square bracket) is ignored. Therefore, this is also a valid tuple declaration:
var tup = [tupletag: 1, 2, 3, "four", 5, ];
The kind-of-formal definition of the tuple literal:
[
<symbol>
:
( <rs-expr>
,
)* ]
Where <rs-expr> is the so-called right side expression - the expression that can appear on the right side of the =
(assignment) operator.
There are three macro variables that can be used for logging and debugging purposes:
__FILE__
- full path of current file;__FOLDER__
- full path of current folder;__LINE__
- current line number in the file;__TRACE__
- actually is an instruction that creates current call trace snapshot as a vector of triplets. Each triplet is a vector of three elements where:[0]
- integer, line number;[1]
- symbol, function name;[2]
- symbol, file name.