It's a destructuring assignment. Specifically, an object destructuring assignment. It might help to see it rewritten in a more verbose way.
The curly braces are used only for import when export is named. If the export is default then curly braces are not used for import.
Introduction to the JavaScript const keywordES6 provides a new way of declaring a constant by using the const keyword. The const keyword creates a read-only reference to a value. By convention, the constant identifiers are in uppercase. Like the let keyword, the const keyword declares blocked-scope variables.
Yes, it works, but only up to a single line just after an 'if' or 'else' statement. If multiple lines are required to be used then curly braces are necessary. if(foo) Dance with me; else Sing with me; The following will NOT work the way you want it to work.
It's a destructuring assignment. Specifically, an object destructuring assignment.
It might help to see it rewritten in a more verbose way.
const abc = Object.abc;
const def = Object.def;
It's a shorthand way to initialise variables from object properties.
const name = app.name;
const version = app.version;
const type = app.type;
// Can be rewritten as:
const { name, version, type } = app;
You can do the same kind of thing with arrays, too.
const a = items[0];
const b = items[1];
const c = items[2];
// Can be written as:
const [a, b, c] = items;
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