The specification was approved by ECMA International on June 22. ECMAScript 2021 includes the following features:
String.prototype.replace, meanwhile, affects only the first occurrence when used with a string argument. The proposed solution would add a
replaceAllmethod to the String prototype, providing developers with a straightforward solution.
AggregateError, a new error type to represent multiple errors at once.
Promise.any, a promise combinator that short-circuits when an input value is fulfilled.
Promise.anyaccepts an iterable of promises and returns a single promise that resolves with the value of that promise. If not promises of the iterable fulfill, then the return promise is rejected with
AggregateError. This method is the opposite of
WeakRef, for referring to a target object without preserving it from garbage collection. This proposal encompasses major new pieces of functionality: creating weak references to objects with the
WeakRefcodeclass, and running user-defined finalizers after objects are garbage collected, using the
FinalizationRegistry, another new feature, are considered advanced features, with their correct use requiring careful thought. They are best avoided, if possible.
FinalizationRegistry, to manage registration and de-registration of cleanup operations performed when target objects are garbage collected.
Array.prototype.sortis being made more precise, to reduce the amount of cases resulting in an implementation-defined sort order.
- Separators for numeric literals, enabling developers to make numeric literals more readable by creating a visual separation between groups of digits. Large numeric literals are difficult to parse visually, particularly when there are long digit repetitions.
- Logical assignment operators, combining logical operators and assignment expressions. Underlying this proposal is the reasoning that there are a dozen mathematical assignment operators but none for often-used logical operators.
ECMAScript 2021 follows ECMAScript 2020, which was formally approved last June. ECMAScript 2020 introduced features ranging from a new
import facility for loading modules to a
BigInt type to work with arbitrary precision integers.