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. The 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 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.
More InformationRelated ArticlesECMAScript 2018 Is Feature Complete JavaScript The Language With Two Names The JavaScript Encyclopedia Work In Progress JavaScript Added To Oxford English Dictionary JavaScript 6 EcmaScript 2015 Final Approval 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.
Comments
or email your comment to: comments@i-programmer.info <ASIN:1871962579> <ASIN:1871962560> <ASIN:1871962625> |
Last Updated ( Thursday, 01 July 2021 ) |