Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of ES6 Object Destructuring Assignment - Defaults
/* ES5 */
var catMaru = { name: 'Maru', mittens: true };
var name = catMaru.name;
var mittens = catMaru.mittens;
var likes = catMaru.likes === undefined ? 'boxes' : catMaru.likes;
/* >= ES6 */
var catMaru = { name: 'Maru', mittens: true };
var { name, mittens, likes = 'boxes' } = catMaru;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment