Reputation: 2611
({ body: { customer } } = await callCreateCustomer({
email: createRandomEmailAddress(),
key: 999,
password: 'password',
}));
I don't understand what it means when you have ()
around the whole expression?
What does it do?
Upvotes: 12
Views: 390
Reputation: 35253
This is Destructuring Assignment without declaration. Here customer
variable is already declared above and a value is being assigned with response.body.customer
From the documentation:
The parentheses ( ... ) around the assignment statement are required when using object literal destructuring assignment without a declaration.
{a, b} = {a: 1, b: 2}
is not valid stand-alone syntax, as the {a, b} on the left-hand side is considered a block and not an object literal.However,
({a, b} = {a: 1, b: 2})
is valid, as isvar {a, b} = {a: 1, b: 2}
Your ( ... ) expression needs to be preceded by a semicolon or it may be used to execute a function on the previous line.
Upvotes: 16