Three types:
^0x[A-Fa-f0-9]+
.^0[0-7]+
.
If a token has a leading zero, but also has any 8
or 9
digits, it will be interpreted as a decimal.[0-9]+
.string | name | decimal |
---|---|---|
\0 | Null | 0 |
\b | Backspace | 8 |
\t | Tab | 9 |
\n | New line | 10 |
\v | Vertical tab | 11 |
\f | Form feed | 12 |
\r | Carriage return | 13 |
\" | Double quote | 34 |
\' | Apostrophe | 39 |
\\ | Backslash | 92 |
Along with several character code escape sequences:
"\123" == "S"
and "\12" == "\n"
. The interpretation is greedy, so it will consume as many octal digits after the backslash as it can, i.e., "\127" == "W"
, but "\128" == "\n8"
, since 8
is not an octal digit.\x
, and always require both digits. E.g., "\xFE" == "þ"
, "\x0a" == "\n"
.\u
, followed by four hexadecimal digits. E.g., "\u00FE" == "þ"
.var l = {a: 1, b: 7};
var r = {a: 5, c: 10};
{...l, ...r}
> { a: 5, b: 7, c: 10 }
{...r, ...l}
> { a: 1, c: 10, b: 7 }
{...l, ...r, a: 100}
> { a: 100, b: 7, c: 10 }
{a: 100, ...l, ...r}
> { a: 5, b: 7, c: 10 }
function defaultNumber() {
console.log('creating default number');
return 100;
}
function printNumber(x = defaultNumber()) {
console.log('x =', x);
}
printNumber(22);
> x = 22
printNumber(33);
> x = 33
printNumber();
> creating default number
> x = 100
This demonstrates that defaultNumber()
does not get called when the module is loaded, nor when printNumber(someX)
is called, but only when printNumber()
is called without a value.