const { message } 1

const { message }

const { bar } = foo; // where foo = { bar:5, baz:2, bat: 10 };
/* This creates a constant with the name 'bar', which has a value of 5 */
const { message } = new assert.AssertionError({
  actual: 1,
  expected: 2,
  operator: 'strictEqual'

Here is what the above code is Doing:
1. It creates a constant called ‘bar’ with the value of 5.
2. It creates a constant called ‘message’ with the value of the ‘message’ property of the object that is passed in.

The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.

Destructuring is a convenient way of extracting multiple values from data stored in (possibly nested) objects and Arrays. It can be used in locations that receive data (such as the left-hand side of an assignment).

The object and array literal expressions provide an easy way to create ad hoc packages of data. They are useful for communications between cooperating functions, or to encode and decode data in a compact format.

The destructuring assignment uses similar syntax, but on the left-hand side of the assignment to define what values to unpack from the sourced variable.

Destructuring also works great with complex functions that have a lot of parameters, default values, and so on. It can be hard to keep track of what’s what.

Similar Posts