JS: New Features 2016 to 2021
Since 2015, new features are added to JavaScript the language each year.
JS2015
JS2016
- Array.prototype.includes
- The power operator
**
. Example,3 ** 2 === 9
. 〔see Operators〕
JS2017
- Object.entries
- Object.values
- Object.getOwnPropertyDescriptors
- String.prototype.padStart
- String.prototype.padEnd
async
keyword for functions andawait
keyword. (xtodo )
JS2018
Destructure object rest properties
For example, we have let { c, ...remainProperties } = { a:1, b:2, c:3 };
, then
c is 3. remainProperties is { a:1, b: 2 }
.
See:
• Destructuring Assignment
• Function Argument Destructure
Spread operator for object literal
For example,
{ ...{ a:1, b:2}, c:3 }
becomes
{ a:1, b:2, c:3 }
.
See: Spread Operator
Regex Features
- The dotAll flag:
s
, make the dot.
also match newline characters. See dotAll Flag - Match characters by Unicode character property:
\p{PropertyValue}
and\P{PropertyValue}
. See RegExp Unicode Property - Named capture group. See RegExp Syntax
- lookbehind assertions. See RegExp Syntax
promise finally, async iteration
Promise.prototype.finally
. (xtodo )- Asynchronous iteration. (xtodo )
JS2019
- Array.prototype.flat
- Array.prototype.flatMap
- Object.fromEntries
- String.prototype.trimStart
- String.prototype.trimEnd
Symbol.prototype.description
〔see Symbol.prototype〕
JS2020
globalThis
- A variable that is alias to the Global Object the Global Object
??
- Nullish Coalescing Operator
?.
- Optional Chaining Operator
String.prototype.matchAll
- String.prototype.matchAll
- Property Order Guaranteed
- Now object property's order is guaranteed by spec.
bigint
xtodo
const x = 10n; console.log( typeof x === "bigint" ); // true
dynamic import
xtodo
import * as xyz from "./xyz.js";
import.meta
xtodoexport {abc} from "./xyz.js"; export * from "./xyz.js";
import() syntax
xtodoPromise.allSettled
xtodoJS2021
- Number Separator
-
Numbers can have lowline _ between digits. For example, you can write
1_000
. - Logical AND assignment operator
x &&= y
-
Assigns y to x if
Boolean(x)
eval totrue
. see JS: Operators - Logical OR assignment operator
x ||= y
-
Assigns y to x if
Boolean(x)
eval tofalse
. - Logical Nullish assignment operator
x ??= y
-
Assigns y to x if
x
is null or undefined
- String.prototype.replaceAll
Promise.any
- weak reference