O'Reilly logo

Hands-On Microservices with Node.js by Diogo Resende

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Destructuring

Destructuring is the convenient method of constructing (target) or extracting (source) properties from an object. It gives the developer the ability to pick specific object properties from arguments or swap variable values, for example:

// head = 1, tail = [ 2, 3, 4]let [ head, ...tail ] = [ 1, 2, 3, 4 ];// list = [ "john", "jane" ]let { users: list } = { users: [ "john", "jane" ] };

You can also have more complex destructuring in assignments and function arguments. You can also assign default values:

class Rectangle {    constructor({ width = 100, height = 50 } = {}) {        this.width = width;        this.height = height;    }}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required