ECMAScript is a scripting-language specification designed to standardize JavaScript. It was first published in 1997 and ECMAScript 2019 is the tenth edition of the standard. This article is a brief summary of new features introduced in ECMAScript 2019.
Function.prototype.toString() method
The method isn’t new, but it was revised. Now the toString()
method returns
source code of the applied function as it is – with all white spaces, new lines,
and comments. Earlier they were removed.
Use example:
Array.prototype.flat() and Array.prototype.flatMap()
Array.prototype.flat()
creates a new flattened array by turning the specified
array of values which may be more arrays to the defined depth. By default, the
depth value is 1
. You can use Infinity
value to create a one-dimension array.
Array.prototype.flatMap()
is a kind of mix between array.flat()
and
array.map()
. The method maps each element via the specified function first
and then creates a new array and fills it by flattening the result.
String.prototype.trimStart() and String.prototype.trimEnd()
String.prototype.trimStart()
removes the whitespace characters from the
beggining of a string and string.prototype.trimEnd() removes them from the end.
There are identical methods string.trimLeft()
and string.trimRight()
that are
aliases of the string.trimStart()
and string.trimEnd()
, respectively.
Object.prototype.fromEntries()
The method converts a list of key-value pairs into an object. It only accepts iterable objects (Array or Map).
Stable Array.prototype.sort()
Earlier an array that has more than 10 items used unstable QuickSort algorithm. Now stable TimSort is used instead.
Optional catch parameter in try…catch
The method allows not to specify the unused binding (parameter) of the catch clause.
Symbol.prototype.description
Prior to ECMAScript 2019, to get a description we used toString()
method. Now
we have an intuitive read-only description
property - a string returning the
optional description of Symbol objects.
Improved JSON.stringify() formatting
JSON.stringify()
is prevented from returning lone surrogates without
representation them in UTF-8 standard. Since lone UTF-16 surrogates cannot be
encoded as UTF-8, ECMAScript 2019 represents them with JSON escape sequences.
JSON superset
Now the JSON subset is a part of ECMAScript syntax. It’s a more specific update and doesn’t provide new features but fix old bugs.