8 NEW FEATURES in JavaScript ES2019

Published by Rienz Otiong on

I personally love how JavaScript keeps improving and adding more features. TC39 has finished and approved this 8 features for ES2019 which has 4 stages and those stages are.

  • Stage 0: Strawman
  • Stage 1: Proposals
  • Stage 2: Drafts
  • Stage 3: Candidates
  • Stage 4: Finished/Approved

Here are the links for you can see all the proposals on Stage 0, Stage 1 – 3 and Final Stage.

I also don’t like introductions so let’s start naming and explaining this features one by one.

 

 

Optional Catch Binding

The proposal of Optional Catch Binding is to be able to optionally remove the catch binding where it would not be used.

the unused binding can now be remove.

 

 

JSON superset

The motivation of this proposal is that JSON strings can contain unescaped U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR characters while ECMAScript strings cannot. Before ES2019 was deployed it would produce an error of SyntaxError: Invalid or unexpected token.

 

 

Symbol Description

Symbols was introduce in ES2015 and has very unique features. In ES2019, it can now provide its given description. Its goal is to avoid indirectly getting the provided description from Symbol.prototype.toString.

 

 

Function.prototype.toString – Revision

We already have the toString method within the function prototype before however in ES2019 it was revised and include the comment that is within the function but note that it doesn’t work on Arrow Functions.

 

 

Object.fromEntries

It is a reverse method for Object.entries which can be one of the ways to clone an object.

However like I said on my Spread Operator article, Be careful because any embedded object/array is simply being copied by reference.

 

 

Well-formed JSON.stringify

This was also proposed by the same person and is related on the feature JSON superset. Instead of returning unpaired surrogate code points as single UTF-16 code units, ES2019 represent them with JSON escape sequences.

 

 

String.prototype trimStart and trimEnd

We already have trim method in String prototype which removes spaces between the start and end of the string. However now ES2019 introduced trimStart and trimEnd.

 

 

Array.prototype flat and flatMap

flat method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth. The depth by default to 1 which flattens the first layer of nested arrays on the array.

 

flatMap is similar to flat and related to map in which it maps the array then flattens it afterwards.

 

 

Extra

I would like to also highlight some of the useful upcoming features that are now in Stage 3.

 


2 Comments

John Munsch · February 13, 2019 at 11:50 pm

Hi. Really good content. Small bit of feedback on your syntax highlighting. Whichever style you’ve picked shows all of the comments in barely there grey on top of the black background, rendering them almost unreadable for someone with any eye issues at all.

You might consider choosing a different theme for your code examples to provide a little more contrast.

    Rienz · February 14, 2019 at 7:56 am

    I apologize for that. I will change it for the majority. thanks for your feedback. Cheers 🙂

Leave a Reply

%d bloggers like this: