I'm currently following the dynamic imports guide in Webpack documentation and came across this following example:
async function getComponent() {
const element = document.createElement('div');
const { default: _ } = await import('lodash');
element.innerHTML = _.join(['Hello', 'webpack'], ' ');
return element;
}
getComponent().then((component) => {
document.body.appendChild(component);
});
Question 1:
What is the syntax used in const { default: _ } = await import('lodash');?
I understand that { default: _ } is needed because of how Webpack import CommonJS modules. But what does it mean to have it on the left side of the assignment?
I tried to get the answer online and was fruitless after much effort. I am pretty sure this is unrelated to Webpack itself, but I don't really know how I should phrase my question to get the answer from Google instead of asking it here. So for my future improvement:
Question 2: How would you formulate this question to get an answer from the search engine?