ECMAScript 2020 spec for JavaScript approved

The latest standard for JavaScript, ECMAScript 2020 introduces new features for module loading, precision integers, and strings

ECMAScript 2020 spec for JavaScript approved

ECMAScript 2020, the lates version of the official specification underlying JavaScript, was formally approval by ECMA International, and the ECMA technical committee overseeing the specification, on June 16. 

ECMAScript 2020 introduces multiple features ranging from a new import() facility for loading modules to a new BigInt type for working with arbitrary precision integers. 

Specific features introduced by ECMAScript 2020 include:

  • A “function-like” import() module loading syntax to asynchronously import modules with a dynamic specifier. The proposal adds an import(specifier) syntactic form, acting in many ways like a function. It returns a promise for the module namespace object of the requested module, created after fetching, instantiating, and evaluating a module’s dependencies, along with the module itself. The specifier will be interpreted the same way as in an import declaration. While specifier is a string, it is not necessarily a string literal; thus, code like import(`./language-packs/${navigator.language}.js`) will work. This was not possible with the usual import declarations. With the plan, import() is proposed to work in both modules and scripts, giving script code an easy asynchronous entry point into the module world and allowing it to start running module code.
  • BigInt, a new number primitive for working with arbitrary precision integers. BigInt can represent numbers larger than two to the 53rd power, the largest number JavaScript can represent reliably with the Number primitive. A BigInt is created by appending n to the end of the integer or by calling the constructor.
  • The matchAll method for strings, to produce an iterator for all matched objects generated by a global regular expression. The rationale behind this proposal is that if a developer has a string and either a sticky or a global regular expression with multiple capturing groups, the developer might want to iterate through all the matches, for which there are currently several options but with limitations. String#matchAll addresses issues by providing access to all capturing groups and not visibly mutating the regular expression object in question.
  • Promise.allSettled, a new Promise combinator that does not short-circuit. This returns a promise that is fulfilled with an array of promise state snapshots, but only after the original promises have settled, i.e. have been either fulfilled or rejected.
  • globalThis, providing a universal way to access the global this value.
  • A dedicated export * as ns from ‘module’ syntax to use within modules.
  • Increased standardization of for-in enumeration order, partially specifying enumeration order in JavaScript.
  • import.meta, a host-populated object in Modules that can contain contextual information. This serves as a JavaScript metaproperty, holding host-specific metadata about the current module.
  • Nullish coalescing, a value selection operator for better handling of cases involving property accesses. It is a syntax feature to improve working with “nullish” values (null or undefined).
  • Optional chaining, a property access and function invocation operator that will short-circuit if the value to access/invoke is nullish. 

The last update to ECMAScript, ECMAScript 2019, featured capabilities such as prototype.flatMap for nested arrays.

Copyright © 2020 IDG Communications, Inc.