|ES2021 Improves Promises Support|
|Written by Ian Elliot|
|Thursday, 01 July 2021|
The twelfth edition of ECMAScript, ES2021, has been approved with improved support for promises and new logical assignment operators.
The improvements to support for Promises comes in the form of promise.any. ES2020 introduced promise.allSettled that provided a way to run multiple promises in parallel until they were all settled, either as fulfilled or as rejected. promise.any is a variation on this that takes an array of promises and returns the first promise to be fulfilled successfully. If all the promises reject, it too rejects.
Logical assignment operators have been extended with the ability to combine logical operations such as ??, &&, or || with the assignment operator = so you can use expressions such as:
x ??= 3
to assign 3 to x when x is null or undefined.
Numeric separators are another addition, providing a way to make numeric literals more readable by creating a visual separation between groups of digits.The layout ends up looking like the way numbers would when included in a written document:
1_000_000_000 // Ah, so a billion
let fee = 123_00; // $123 (12300 cents, apparently)
WeakRef is an addition that provides two major new pieces of functionality, according to the original proposal. The addition can be used to create weak references to objects with the WeakRef class, and also to run user-defined finalizers after objects have been garbage collected so objects from WeakRef variables can be safely removed to free up space.
The final addition is String.replaceAll. As the name suggests, this adds a way to replace all the occurrences of a given string.
All minor but reasonable improvements - let us hope for no more revolutions.
or email your comment to: email@example.com
|Last Updated ( Thursday, 01 July 2021 )|