Paul Krill
Editor at Large

ECMAScript 2021 spec for JavaScript crosses the finish line

news
Jun 23, 20212 mins

Latest version of the official specification for JavaScript introduces enhancements to strings, promises, and object references.

man running across finish line
Credit: Thinkstock

ECMAScript 2021, the latest version of the official specification underlying JavaScript, has been formally approved, adding capabilities for strings and promises.

The specification was approved by ECMA International on June 22. ECMAScript 2021 includes the following features:

  • String.prototype.ReplaceAll, providing developers with a way to replace all instances of a substring in a string without the use of a global regexp. There is evidence that developers are trying to accomplish this in JavaScript, with a global regexp currently the most-common way of achieving this. String.prototype.replace, meanwhile, affects only the first occurrence when used with a string argument. The proposed solution would add a replaceAll method to the String prototype, providing developers with a straightforward solution.
  • AggregateError, a new error type to represent multiple errors at once.
  • <a href="https://github.com/tc39/proposal-promise-any" rel="nofollow">Promise.any</a>, a promise combinator that short-circuits when an input value is fulfilled. Promise.any accepts 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 Promise.all.
  • 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 WeakRefcode class, and running user-defined finalizers after objects are garbage collected, using the FinalizationRegistry class. WeakRef and 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.sort is 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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author