ECMAScript 2020

29 May 2020 at 13:00 by ParTech Media - Post a comment

Since 2015 ECMAScript, the formal specification of the JavaScript language, has been getting annual updates that come out every June. These updates consist of all proposals that have achieved the fourth stage. This stage contains finished proposals that have been signed off by all the ECMAScript editors, shipped in at least two compatible implementations and passed acceptance testing. After the backlog of proposals dealt within ECMAScript 2015, the annual updates have tended to be smaller, with a mix of new features, syntax improvements and updates that cover slight omissions in the standard.

ECMAScript also comes with an update in June 2020. It introduces various features. Specific features for ECMAScript 2020 are:

  • 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 tot eh 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.

  • 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.

Latest