({ 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?
It's a new feature that introduced in ES6 and is called arrow function. The left part denotes the input of a function and the right part the output of that function.
The syntax of JavaScript is the set of rules that define a correctly structured JavaScript program. The examples below make use of the log function of the console object present in most browsers for standard text output.
What is this? In JavaScript, the this keyword refers to an object. Which object depends on how this is being invoked (used or called). The this keyword refers to different objects depending on how it is used: In an object method, this refers to the object.
JavaScript functions are defined with the function keyword. You can use a function declaration or a function expression.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With