What is Lightning Web Components (LWC), and how does its architecture differ from Aura components?
Answer
Basics: Both build Lightning UI (record pages, apps, utility bar, quick actions, Experience Cloud). Aura came first (2014); LWC arrived in 2019 and relies on what browsers do natively, so there is less framework code to download and run.
How it works:
- LWC bundle:
.htmltemplate,.jsclass, optional.cssand.js-meta.xmlfor exposure targets. - Decorators:
@api(public property or method),@wire(reactive data from Apex or the Lightning Data Service),@track(only needed for deep mutation tracking of objects or arrays). - Communication: properties down,
CustomEventup, and Lightning Message Service for unrelated components. - Aura uses
.cmpmarkup, controller and helper JS, and application or component events.
Advanced / deep dive: Performance: LWC avoids Aura's heavy virtual component layer, and uses standard lwc:if directives (legacy if:true still works). Security: Lightning Web Security (LWS) is the newer sandbox that replaces Lightning Locker. Interop: an Aura component can contain LWC, but LWC cannot contain Aura. Testing: LWC supports Jest unit tests (@salesforce/sfdx-lwc-jest). Tooling: standard ES module imports, plus lightning/* base components and @salesforce/* imports. Some features remain Aura-only or Aura-first for specific legacy surfaces; verify current support per feature. Migration is gradual: wrap LWC inside Aura where needed.
Code / config example:
<!-- helloWorld.html -->
Hello, {name}!