Académique Documents
Professionnel Documents
Culture Documents
Control characters
Control characters have no visual representation but are used to control
the interpretation of the text.
White space
White space characters improve the readability of source text and
separate tokens from each other. These characters are usually
unnecessary for the functionality of the code. Minification tools are often
used to remove whitespace in order to reduce the amount of data that
needs to be transferred.
White space characters
Code Abbreviatio Escape
Name Description
point n sequence
Character
U+0009 <HT> Horizontal tabulation \t
tabulation
U+000B Line tabulation <VT> Vertical tabulation \v
Page breaking control
U+000C Form feed <FF> \f
character (Wikipedia).
U+0020 Space <SP> Normal space
Normal space, but no point
U+00A0 No-break space <NBSP>
at which a line may break
Other Unicode Spaces in Unicode on
Others <USP>
space characters Wikipedia
Line terminators
In addition to white space characters, line terminator characters are used
to improve the readability of the source text. However, in some cases, line
terminators can influence the execution of JavaScript code as there are a
few places where they are forbidden. Line terminators also affect the
process of automatic semicolon insertion. Line terminators are matched
by the \s class in regular expressions.
Only the following Unicode code points are treated as line terminators in
ECMAScript, other line breaking characters are treated as white space (for
example, Next Line, NEL, U+0085 is considered as white space).
Comments
Comments are used to add hints, notes, suggestions, or warnings to
JavaScript code. This can make it easier to read and understand. They can
also be used to disable code to prevent it from being executed; this can
be a valuable debugging tool.
function comment() {
/* This is a one line JavaScript comment */
console.log('Hello world!');
}
comment();
You can also make multiple-line comments, like this:
function comment() {
/* This comment spans multiple lines. Notice
that we don't need to end the comment until we're done. */
console.log('Hello world!');
}
comment();
You can also use it in the middle of a line, if you wish, although this can
make your code harder to read so it should be used with caution:
function comment(x) {
console.log('Hello ' + x /* insert the value of x */ + ' !');
}
comment('world');
In addition, you can use it to disable code to prevent it from running, by
wrapping code in a comment, like this:
function comment() {
/* console.log('Hello world!'); */
}
comment();
In this case, the console.log() call is never issued, since it's inside a
comment. Any number of lines of code can be disabled this way.
Keywords
Reserved keywords as of ECMAScript 2015
break
case
catch
class
const
continue
debugger
default
delete
do
else
export
extends
finally
for
function
if
import
in
instanceof
new
return
super
switch
this
throw
try
typeof
var
void
while
with
yield
enum
The following are only reserved when they are found in strict mode code:
implements
interface
let
package
private
protected
public
static
The following are only reserved when they are found in module code:
await
Boolean literal
See also Boolean for more information.
true
false
Numeric literals
Decimal
1234567890
42
Binary
Octal
Hexadecimal
Object literals
See also Object and Object initializer for more information.
var o = { a: 'foo', b: 'bar', c: 42 };
// instead of
var o = { a: a, b: b, c: c };
Array literals
See also Array for more information.
[1954, 1974, 1990, 2014]
String literals
'foo'
"bar"
New in ECMAScript 2015. With Unicode code point escapes, any character
can be escaped using hexadecimal numbers so that it is possible to use
Unicode code points up to 0x10FFFF. With simple Unicode escapes it is
often necessary to write the surrogate halves separately to achieve the
same.
See
also String.fromCodePoint() or String.prototype.codePointAt().
'\u{2F804}'
Template literals
See also template strings for more information.
`string text`
{ 1 2 ;} 3;
2. A semicolon is inserted at the end, when the end of the input stream
of tokens is detected and the parser is unable to parse the single input
stream as a complete program.
a = b;
++c;
3. A semicolon is inserted at the end, when a statement with restricted
productions in the grammar is followed by a line terminator. These
statements with "no LineTerminator here" rules are:
return;
a + b;