Declare JavaScript variable as reference

Viewed 31

I recall there being a feature of Javascript, such that the something resembling the following is possible:

let foo = { bar: "bar" };
let { baz } = foo.bar;

baz = "baz";
console.log(foo.bar); // "baz"

Does such a feature exist? If so, what is the correct syntax to get this to work?

1 Answers

Maybe you are looking for destructuring assignment

let foo = { bar: "baz" };
let { bar } = foo;

console.log(bar); // "baz"

Related