ES2021 Improves Promises Support
Written by Ian Elliot   
Thursday, 01 July 2021

The twelfth edition of ECMAScript, ES2021, has been approved with improved support for promises and new logical assignment operators.

ECMAScript is the language standard on which JavaScript is based, though JavaScript predates it from its original development at NetScape. The standard was originally set out as a formal description of JavaScript to guide the future of the language. 

ecmaThe improvements to support for Promises comes in the form of promise.any. ES2020 introduced promise.allSettled that provided a way to run multiple promises in parallel until they were all settled, either as fulfilled or as rejected. promise.any is a variation on this that takes an array of promises and returns the first promise to be fulfilled successfully. If all the promises reject, it too rejects.

Logical assignment operators have been extended with the ability to combine logical operations such as ??, &&, or || with the assignment operator = so you can use expressions such as:

x ??= 3

to assign 3 to x when x is null or undefined.

Numeric separators are another addition, providing a way to make numeric literals more readable by creating a visual separation between groups of digits.The layout ends up looking like the way numbers would when included in a written document:

1_000_000_000 // Ah, so a billion
101_475_938.38 // And this is hundreds of millions
let fee = 123_00; // $123 (12300 cents, apparently)

WeakRef is an addition that provides two major new pieces of functionality, according to the original proposal. The addition can be used to create weak references to objects with the WeakRef class, and also to run user-defined finalizers after objects have been garbage collected so objects from WeakRef variables can be safely removed to free up space.

The final addition is String.replaceAll. As the name suggests, this adds a way to replace all the occurrences of a given string.

All minor but reasonable improvements - let us hope for no more revolutions.

ecma

 

 

  • Ian Elliot is the author of several JavaScript titles. Just JavaScript: An Idiomatic Approach is intended for programmers who are familiar with another language. It takes a radical look at JavaScript that takes account of the way it is object-based. JavaScript Async covers asynchronous programming in JavaScript, async/await, Promises, Service Workers and so on.  His most recent book, JavaScript Bitmap Graphics with Canvasshows you how to use Canvas to create graphics without resorting to a library of any kind.

 

More Information

ES2021 New Features

Related Articles

How Is JavaScript Doing?

ESLint Adds ES2020 Support

ES2020 Finalized

ECMAScript 2018 Is Feature Complete

ECMAScript 2016 Approved

JavaScript The Language With Two Names    

The JavaScript Encyclopedia Work In Progress 

JavaScript Added To Oxford English Dictionary 

JavaScript 6 EcmaScript 2015 Final Approval 

JavaScript 20 Years Old Today 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


The Art Of Computer Programming - A Great Present
15/12/2024

If you are looking for a programmer present this holiday season, there is one book, or set of books, that should be top of any list... Donald Knuth's The Art of Computer Programming.



Pico 2W Announced But There Is A Surprise!
25/11/2024

Raspberry Pi released the Pico 2 a few months ago and we have been waiting for the Pico 2W since then. But Pimoroni beat them to the draw with the Pico Plus 2W based on the RM2 radio module and hinted [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

<ASIN:1871962579>

<ASIN:1871962560>

<ASIN:1871962625>

Last Updated ( Thursday, 01 July 2021 )