my linter is giving me trouble about destructuring.

When I'm trying to destructure, it makes me an error, like in the following snippet :
const data = {
status: 'example',
};
let status = 'foo';
{
status,
} = data;
console.log(status);
Is there any ways to use destructuration when the variable already exists?
Using let again :
const data = {
status: 'example',
};
let status = 'foo';
let {
status,
} = data;
console.log(status);
Add parenthesis around destructuring
From the documentation: Assignment without declaration
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.
const data = {
status: 'example',
};
let status = 'foo';
({ status } = data);
console.log(status);
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