You've successfully subscribed to Smartcodehub ™ Blog
Great! Next, complete checkout for full access to Smartcodehub ™ Blog
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
What's new in ECMAScript 2019?

What's new in ECMAScript 2019?

Neeraj Dana
Neeraj Dana

Many people apprehend that there's a typical procedure for Javascript’s latest releases and a committee behind that. during this post, i'll justify who makes the ultimate appeal any new specification, what's the procedure for it, and what is new in ES2019.

The language specification that drives JavaScript is named ECMAScript. there's a team behind that referred to as Technical Committee thirty-nine [TC39] that reviews each specification before adopting.

Every modification goes through a method with stages of maturity.

Stage 0: Ideas/Strawman
Stage 1: Proposals
Stage 2: Drafts
Stage 3: Candidates
Stage 4: Finished/Approved
A feature that reaches Stage four can presumably be a part of the language specification.

Let's dive into the items that are recently into the specification underneath ES2019.

Array.prototype


Array.prototype.flat() planned to flatten arrays recursively up to the required depth and returns a replacement array.

Syntax: Array.prototype.flat(depth)
depth — Default worth one, Use time to flatten all nested arrays.

const numbers = [1, 2, [3, 4, [5, 6]]];
// Considers default depth of 1
numbers.flat(); 
> [1, 2, 3, 4, [5, 6]]
// With depth of 2
numbers.flat(2); 
> [1, 2, 3, 4, 5, 6]
// Executes two flat operations
numbers.flat().flat(); 
> [1, 2, 3, 4, 5, 6]
// Flattens recursively until the array contains no nested arrays
numbers.flat(Infinity)
> [1, 2, 3, 4, 5, 6]

Array.prototype.flatMap() maps every part employing a mapping perform and flattens the result into a replacement array. It’s clone of the map operation followed by a flat of depth one.

Syntax: Array.prototype.flatMap(callback)
callback: perform that produces a part of the new Array.

const numbers = [1, 2, 3];
numbers.map(x => [x * 2]);
> [[2], [4], [6]]
numbers.flatMap(x => [x * 2]);
> [2, 4, 6]

Object.fromEntries


Object.fromEntries performs the reverse of Object.entries . It transforms a listing of key-value pairs into AN object.

Syntax: Object.fromEntries(iterable)
iterable: AN iterable like Array or Map or objects implementing the iterable protocol

const records = [['name','Mathew'], ['age', 32]];
const obj = Object.fromEntries(records);
> { name: 'Mathew', age: 32}
Object.entries(obj);
> [['name','Mathew'], ['age', 32]];

String.prototype.


trimStart() removes whitespace from the start of a string and trimEnd() removes whitespace from the tip of a string.

const greeting = ` Hello Javascript! `;
greeting.length;
> 19
greeting = greeting.trimStart();
> 'Hello Javascript! '
greeting.length;
> 18
greeting = 'Hello World!   ';
greeting.length;
> 15
greeting = greeting.trimEnd();
> 'Hello World!'
greeting.length;
> 12

Optional Catch Binding


Prior to the new specification, it absolutely was needed to own associate exception variable bind to a catch clause. ES2019 created it ex gratia.