In this article, I simply try to summarize new features of es2017.

Major new features:

  • Async & Await
  • Shared memory and atomics

Minor new features:

  • Object.values and Object.entries
  • String padding
  • Object.getOwnPropertyDescriptors()
  • Trailing Commas in Function Parameter Lists

Async & Await

The async function declaration defines an asynchronous function, which returns an AsyncFunction object.

Internally, async functions work much like generators, but they are not translated to generator functions.

We can only use await inside async function.

async function getUser(){  
  //Your logic goes here
  const department = await getDepartment();
}

getDepartment is an async function or normal function which return a promise.

For example:

Object.entries()

If a JavaScript data structure has keys and values then an entry is a key-value pair, formatted as a 2-element Array.

Object.entries({ one: 1, two: 2 })  
//=> [ [ 'one', 1 ], [ 'two', 2 ] ]

If a key in the object is Symbol it is ignored

Object.entries({ [Symbol()]: 'a value', count: 10 });  
//=> [ [ 'count', 10 ] ]

Object.values()

It similarly works like Object.entries, but it return an array of value.

Object.values({ name: 'John', email: '[email protected]' })  
//=> ['John', '[email protected]']

String padding

Use cases for padding strings include:

  • Displaying tabular data in a monospaced font.
  • Adding a count or an ID to a file name or a URL: 'file 001.txt'
  • Aligning console output: 'Test 001: ✓'
  • Printing hexadecimal or binary numbers that have a fixed number of digits: '0x00FF'

Object.getOwnPropertyDescriptors()

Object.getOwnPropertyDescriptors() return an object describing the attributes of property of an object.

const user = {name:'john', email: '[email protected]'};  
Object.getOwnPropertyDescriptors(user)  
/** output
{ name:
   { value: 'john',
     writable: true,
     enumerable: true,
     configurable: true },
  email:
   { value: '[email protected]',
     writable: true,
     enumerable: true,
     configurable: true } }
*/

Trailing Commas in Function Parameter Lists

Trailing commas in object literal

const user = {  
  name:'john',
  email: '[email protected]',
};

Trailing commas in array literal

const scope = ['email', 'profile',];  

Trailing commas in function parameters

function User(  
  email,
  dob,
) {
  //function body
};

Trailing commas in function invocation

const bob = new User(  
  '[email protected]',
  '10/10/1990',
);

Referenced docs:

Further reading: