introduce

ES10 is the 2019 version of ECMAScript. There are not as many new features in this release as there are in ES6 (2015). However, there are some useful features.

This article introduces the capabilities provided by ES10 in simple code examples. This way, you can quickly learn about new features without complicated explanations.

Of course, you need a basic knowledge of JavaScript to fully understand the new features introduced.

New JavaScript features in ES2019 include:

  • Array#{flat,flatMap}
  • Object.fromEntries
  • String#{trimStart,trimEnd}
  • Symbol#description
  • Try {} catch {} // Optional error parameter binding
  • JSON ⊂ ECMAScript
  • Well-formed json.stringify
  • Stable sort Array#sort
  • The new Function# toString
  • Added BigInt primitive type (stage 3).
  • Dynamic import modules (Stage 3).
  • Standard globalThis object (Stage 3).
  • ES10 Class: private, static & public (stage 3).

Array.flat() & Array.flatMap()

Two new array methods:

The array.flat () method creates a new Array, into which all the subarray elements are merged recursively until the specified depth is reached.

The array.flatmap () method first transforms each element using the map function and then flattens the result to a new Array. It has the same effect as map() followed by calling flat() of depth 1, but flatMap() combines the two into a single method for greater efficiency.

Object.fromEntries()

Converts a two-dimensional array of key-value pairs as elements into an object.

String.protype.matchAll()

The matchAll() method returns an iterator of all the results that match the regular expression string, including the capture group.

String.trimStart() & String.trimEnd()

There are two new String methods to remove whitespace from a String:

The trimStart() method removes whitespace from the beginning of the string. The trimEnd() method removes whitespace from the end of the string.

Symbol.Description

When you create a symbol, you can provide a string as a description. In ES10, there is an accessor to get the description.

An optional Catch parameter variable

In the past, the catch clause in a try/catch statement required a variable. It now allows developers to use try/catch without creating unused error variable bindings.

JSON ⊂ ECMAScript

In versions prior to ES10, the non-escaped line delimiter U+2028 and paragraph delimiter U+2029 were not accepted.

U+2028 is the paragraph separator. U+2029 is the line separator.

Well-formed json.stringify ()

Json.stringify () may return characters between U+D800 and U+DFFF as values with no utF-8 equivalent. However, the JSON format requires UTF-8 encoding. The solution is to represent unpaired alternative code points as JSON escape sequences rather than returning them as a single UTF-16 code unit.

Array.prototype.sort()

Previous implementations of V8 used an unstable quicksort algorithm for arrays containing more than 10 items.

A stable sorting algorithm is when two objects with the same key appear in the sorted output in the same order as in the unsorted input.

A new version of the Function. The toString ()

The toString() method returns a string representing the function’s source code. In ES6, when toString is called on a function, it returns the string representation of the function according to the ECMAScript engine. If possible, it will return the source code, otherwise – a standardized placeholder.

BigInt – An integer of arbitrary precision

BigInt is the seventh primitive type, which is an integer with arbitrary precision. Not just the maximum at 9007199254740992.

Dynamic introduction

Dynamic import() returns a Promise for the requested module. Therefore, you can use async/await to assign imported modules to variables.

Standard globalThis object

Global This was not standardized prior to ES10. In production code, you can “standardize” it by writing:

ES10 Class: private, static & public member variables, functions

Now, the new syntax character # (hash tag) is used to define variables, functions, getters, and setters, as well as constructors and class methods directly in a class.

conclusion

Since ES6 came out in 2015, the language has been in a state of high growth. In this article, we review the features that emerged in ES10 (2019) and introduce some that will remain stable in ES11 (2020) as they are in State 3 and may eventually be standardized in the next release.

Although many of these capabilities may not be necessary for the development of Web applications, they offer the possibility of implementation through trickery or a lot of verbose code.