Literals |
Active Web |
A literal is a script token that represents a value.
This is the token null.
This is the token true or false.
Numeric literals can be written in octal, decimal, hexadecimal or exponent notation.
Octal Notation - A zero as the first digit followed by 0 or more octal digits (0 to 7).
e.g. 012
Decimal Notation - One non zero decimal digit (1 to 9) followed by zero or more decimal digits (0 to 9).
e.g. 15
Hexadecimal Notation - A zero, followed by either x or X, followed by one or more hexadecimal digits (0 to 9 and a to f or A to F).
e.g. 0x2c, 0x2C, 0X2c, 0X2C
Exponential Notation - This notation has several variations. Basically it consists of two parts, the first part being the number and the second part being the exponent. In all cases the exponent is optional. The exponent part is e or E followed by one or more decimal digits (0 to 9).
Variation 1: one or more decimal digits, followed by a full stop, followed by one or more decimal digits, followed by an exponent (e.g. 1.3e2).
Variation 2: A full stop, followed by an optional sign followed by one or more decimal digits, followed by an exponent (e.g. .4e3).
Variation 3: One or more decimal digits, followed by an exponent (e.g. 5e-6).
Putting a zero at the front of a numeric literal that is not in exponential notation is octal notation and not decimal notation. |
String literals are zero or more characters between either single or double quotes. A string character is any character excluding the quote character, backslash and the line terminator. The backslash character is used for escape sequences.
An escape sequence always resolves to a single character. There are several variations of the escape sequence.
Variation 1: A backslash followed by one of ' " \ b f n r t v.
backslash followed by the single or double quote is used to escape the quote character inside the string.
backslash followed by backslash is used to escape the backslash character inside the string.
backslash followed by b is the 'Backspace' character.
backslash followed by f is the 'Form Feed' character.
backslash followed by n is the 'Line Feed' (new line) character.
backslash followed by r is the 'Carriage Return' character.
backslash followed by t is the 'Tab' character.
backslash followed by v is the 'Vertical Tab' character.
Variation 2: A backslash followed by x followed by two hexadecimal characters (0 to 9 and a to z or A to Z). This specifies the numeric value of the character and can only be in the range 0 to 255 (e.g. \x20).
Variation 3: A backslash followed by u followed by four hexadecimal characters (0 to 9 and a to z or A to Z). This specifies the numeric value of the character and can be in the range 0 to 65535 (e.g. \u0020).
A 'Line Terminator' character cannot appear in a string literal, even if preceded by a backslash \. The correct way to cause a line terminator character to be part of the string value of a string literal is to use an escape sequence such as \n or \u000A. |
Topic ID: 150071