JavaScript · Middle · Question 37 of 75
Why do you need dynamic import()?
- ✓Correct answer: To load a module on demand and split it into a separate chunk
- 2To import a module synchronously inside conditions and loops
- 3To re-import the module from scratch on every call
Explanation
const { Chart } = await import('./chart.js') returns a promise of the module. Bundlers create a separate file that loads only when needed - the basis of code splitting and React.lazy. The module is cached and runs once.