Paul Krill
Editor at Large

ECMAScript 2022 blesses class elements, top-level await

news
Jun 27, 20222 mins

Next version of JavaScript standard gains formal approval, while the new capabilities are already supported by browsers.

data digital binary code perspective abstract background
Credit: metamorworks / Getty Images

ECMAScript 2022, the next update to the official standard behind JavaScript, has been formally approved, with new capabilities ranging from class elements to a top-level await capability.

The ECMAScript 2022 specification was approved by ECMA International on June 22. But the features already are available in most browsers, said Robert Palmer, co-chair of the TC39 committee that shepherds the standard, in March. Feature availability in JavaScript engines is more relevant to developers than appearance in the actual specification, Palmer said.

ECMAScript 2022 has the following new features:

  • Top-level await, allowing the await keyword to be used at the top level of modules.
  • New class elements, including public and private instance fields, public and private static fields, and private instance methods and accessors.
  • Static blocks within classes, to perform per-class evaluation initialization.
  • The #x in obj#x in obj syntax, to test for the presence of private fields on objects.
  • Regular expression match indices via the /d/d flag, which offers start and end indices for matched substrings.
  • The cause property on Error objects, to be used to record a causation chain in errors.
  • The at method for Strings, Arrays, and TypedArrays, allowing for relative indexing and for use of Object.hasOwn, an alternative to Object.prototype.hasOwnProperty.

Last June’s ECMAScript 2021 standardized capabilities such as String.prototype.ReplaceAll, for replacing instances of a substring, and the AggregateError error type.

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