What are ES modules and how do import/export work?
Suggested answer
ES modules provide a native JavaScript module system. Named exports: export const PI = 3.14; export function add(a, b) { return a + b; } — imported with exact name: import { PI, add } from './utils.js';. Default export: One per module: export default class MyClass {...} — imported with any name: import MyClass from './myClass.js';. Renaming imports: import { add as sum } from './utils.js';. Namespace import: import * as utils from './utils.js';. Dynamic import: const module = await import('./utils.js'); — lazy-loads modules at runtime. In LWC, every JavaScript file is a module. Salesforce-scoped imports use special paths: import { LightningElement } from 'lwc';, import getAccount from '@salesforce/apex/AccountCtrl.getAccount';.
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.