ES10/ES2019(ECMAScript2019) Features

Prabu Subra
AlphaXcode
Published in
5 min readMar 21, 2019

Introduction:-

Recently, TC39 committee has approved and added few bunch of feature to ECMAScript 2019 Standard, which are ported to major JavaScript engine like V8,SpiderMonkey…

Let’s start explore…

Catch binding:-

If there is no use of exceptions details in catch block, developer can remove catch binding happily. This will remove unused and boilerplate code.

Unicode:-

Firstly, What is unicode?

Unicode provides a unique number for every character, no matter what the platform, no matter what the program, no matter what the language.

To be short, JavaScript internally encode the everything to unicode, not only JavaScript everyone does.

if you want to know more about, how unicodes are handled in ES5 and ES6 refer here.

The unicodes u2028 and u2029 represent Line separator and Paragraph separator repetitively . Before this proposal, JavaScript engines does not infer these two unicodes for string literals. Now string literals understands these unicodes as well.

Nashorn ES6 JS Engine:-

V8 ES10 Engine:-

Apart from the above change, JSON.stringify also improved to return well-formed unicode for alone surrogate.

In a nutshell, A few bunch of characters like emojis need more than 16 bit to represent a single character, to solve this issue, UTF-16 has combined two 16 bits and represent those characters. Individually these characters doesn’t have any meaning. hereafter these alone surrogates are prevented from returning invalid junk characters.

Examples:-

U+1F60D SMILING FACE WITH HEART-SHAPED EYES

In the above table, JavaScript Representation of SMILING FACE WITH HEART-SHAPED EYES is \uD83D\uDE0D, it has two UTF-16 bit unicodes. Individually \uD83D or \uDE0D alone doesn’t represent any character, it should be escaped instead of showing junk characters. for more about unicode representation refer here.

ES6:-

ES10:-

Function.prototype.toString():-

Newly revised to string method will not remove space and lines from source code for functions.

For all the built-in, Built-in, bound functions, it should return NativeFunction string.

For dynamically creating function, it should synthesise the source text.

String:-

Two new methods have added to trim a string.

  1. String.prototype.trimStart()
  2. String.prototype.trimEnd()

Symbol:-

As we know Symbol is built in datatype for unique values and it is used as keys for object, Symbol.iterator and so on, a new Symbol.prototype.description is added to get description from symbol.

Object:-

A new static method Object.fromEntries is added to Object.

To be specific, it converts array of arrays(Array which has nested arrays in it) in to Object, Let’s see, how is it working.

Example:-

In above example, array data can be converted to object key value pairs. After looking above example few questions may raise in our head. let’s try to list.

  1. What if, Array doesn’t have any array inside?

Apparently, it applies only to arrays which are having nested arrays. it converts arrays to objects with only first two elements which is at index 0 and 1, ignore other elements.

2. What if, Nested arrays have more than 2 elements in it?

3. What if, Array inside arrays contains objects?

Instead of object as key, we can use strings to construct pragmatic javascript objects.

Arrays:-

Two methods has added.

  1. Array.prototype.flat
  2. Array.prototype.flatMap

Array.prototype.flat:-

It is originally proposed as Array.prototype.flatten, flattens arrays recursively up to the specified depth, which defaults to 1.

Array.prototype.flatMap:-

Combined flatten and map behaviour for arrays. Flatten the result in to single array.

Conclusion:-

As we know, ECMAScript standards are used in various programming languages like Microsoft’s JScript, Oracle Nashorn Engine, it is strictly based on the language engine to choose which standard to support. let’s keep an eye on TC39 proposal for latest updates.

Thanks for reading!!!

Please feel free to comment your suggestions.

Reference:-

--

--