What to expect from JavaScript ES2017 — The Async Edition

André Neves
Feb 13, 2017 · 7 min read

This is a win for the JS community. A smaller, yet feature-packed, yearly release cycle allows for more consistent growth of the language's specification.

Enter ES2017

Major Features

Async Functions

function fetchData(url) {
return fetch(url)
.then(request => request.text())
.then(text => {
return JSON.parse(text);
})
.catch(err => {
console.log(`Error: ${err.stack}`);
});
}
async function fetchData(url) {
try {
let request = await fetch(url);
let text = await request.text();
return JSON.parse(text);
}
catch (err) {
console.log(`Error: ${err.stack}`);
}
}

Shared Memory and Atomics


Minor Features

Trailing commas in function parameter lists and calls

const trailCommaFn = function(
param1,
param2,
param3,
param4) { // No comma allowed here!
// do something in function body}
const trailCommaFn = function(
param1,
param2,
param3,
param4, // Comma allowed here!
) {
// do something in function body}
// Array
const arr = [
1,
2,
3, // <--- Ok
];
// Object Literal
const obj = {
x: 'foo',
y: 'bar',
z: 'baz', // <--- Ok
}

Object.values/Object.entries

>> Object.entries({ foo: 1, bar: 2 })
[ [ 'foo', 1 ], [ 'bar', 2 ] ]
>> Object.values({ foo: 1, bar: 2 })
[ 1, 2 ]
Object.entries(value : any) : Array<[string,any]>Object.values(value : any) : Array<any>

String Padding

>> console.log('testing'.padStart(12).length)
" testing" is 12
>> console.log('testing'.padStart(12, '_'))
"_____testing" is 12

Object.getOwnPropertyDescriptors

// Given an object `obj`>> Object.create(
Object.getPrototypeOf(obj),
Object.getOwnPropertyDescriptors(obj)
);

Learn More about the TC39 Process


Use ES2017 Features Now

Komenco Blog

React & React Native Development

André Neves

Written by

https://andrenev.es

Komenco Blog

React & React Native Development