In ES5, you do like this:

var emailConfig = { 
        serverName: 'gmail', 
        userName: 'anthony' 

Next, read the emailConfig object and assign its property value to local variables

var emailServer = emailConfig.serverName;
var emailUser = emailConfig.userName;

Here is the equivalent in ES6:

let emailConfig = {
        serverName: 'gmail',
        userName: 'anthony'

let { serverName: emailServer, userName: emailUser } = emailConfig;

The point to notice is that serverName key is the property that you want to look for in the emailConfig object and this key's value is assigned to the emailServer local variable.

Now if the local variable name is the same as the property name, you can write it like this:

let { serverName, userName } = emailConfig;

Consider this nested object:

let emailConfig = {
        serverName: 'gmail',
        credentials: {
            userName: 'anthony',
            password: 'pass'

Next we'll create a local variable named userName whose value will be anthony

let { credentials: { userName } } = emailConfig;

Consider this array:

 let days = ['Monday', 'Tuesday', 'Wednesday'];`

The following statement will assign the value Monday to a variable named firstDay and the value Tuesday to a variable named secondDay

let [firstDay, secondDay] = days;

Assignments in ES6 are pretty powerful.

Looking for a job?
New York

Groundswell Cloud Solutions
Vancouver, Canada

JP/Morgan Chase
Dallas, Texas

Startup (stealth)
London, UK

In Angular what is the difference between ngRoute and ui-router
What exactly does import and export do in JavaScript?
How to return multiple values from a function in ES6
Differences between e.preventDefault(), e.stopPropagation(), and return false;