You need core modern JavaScript before Lightning Web Components (LWC) will make sense. That means variables, functions, arrow functions, classes, destructuring, the spread operator, array methods, promises, async/await and ES modules. You do not need Node.js, npm, React, Angular or any other framework background, because LWC is built on standard browser JavaScript and Salesforce handles the build tooling for you.
If you can read a 40-line JavaScript class and explain what each line does, you are ready. If const { data, error } = result or await getContacts() looks foreign, spend a week or two on JavaScript first. You will learn LWC faster that way than if you try to pick up both at once.
Why LWC needs real JavaScript (and Aura let you get by with less)
An LWC component is a folder with three main files: an HTML template, a JavaScript file and a .js-meta.xml config file. The HTML is deliberately simple. It binds to properties and calls handlers, and that's about it. Every decision, data call, calculation and event lives in the JavaScript file.
So the JavaScript file is the component. Admins who are used to Flow, and Apex developers used to server-side code, tend to underestimate this. The template won't let you write {amount * 1.18} or {contacts.length > 0}. You write a getter in JavaScript and bind to that.
Here is a complete, realistic component. Read it before going any further:
import { LightningElement, api } from 'lwc';
import getContacts from '@salesforce/apex/ContactController.getContacts';
export default class ContactPicker extends LightningElement {
@api recordId;
contacts = [];
searchKey = '';
errorMessage;
get hasContacts() {
return this.contacts.length > 0;
}
handleSearchChange(event) {
this.searchKey = event.target.value;
}
async handleLoad() {
try {
const result = await getContacts({ accountId: this.recordId, searchKey: this.searchKey });
this.contacts = result.map(({ Id, Name, Email }) => ({
id: Id,
label: `${Name} (${Email ?? 'no email'})`
}));
} catch (error) {
this.errorMessage = error?.body?.message;
}
}
handleSelect(event) {
const { id } = event.currentTarget.dataset;
this.dispatchEvent(new CustomEvent('contactselect', { detail: { id } }));
}
}
Those 35 lines use modules, classes, decorators, class fields, getters, this, event objects, async/await, try/catch, destructuring, arrow functions, map, template literals, nullish coalescing, optional chaining and custom events. If you can follow all of it, skip ahead to the self-check. If you can't, the next section tells you what to learn.
The JavaScript concepts LWC uses, mapped to where they appear
This table is the short answer to "how much JavaScript do I need for LWC." Each row is a concept you will use in your first few components.
| JavaScript concept | Where it shows up in LWC | Example |
|---|---|---|
const and let | Local variables in every handler and method | const fields = [NAME_FIELD]; |
ES modules (import / export) | First line of every component; importing Apex methods, schema fields, labels | import { LightningElement, api } from 'lwc'; |
Classes and extends | Every component is a class extending LightningElement | export default class Foo extends LightningElement {} |
| Class fields | Component state that the template reads | searchKey = ''; |
| Getters | Computed values for the template, since templates don't allow expressions | get hasContacts() { return this.contacts.length > 0; } |
this | Reading and setting component state in every method | this.searchKey = event.target.value; |
| Decorators | Public properties, wire adapters, deep tracking | @api recordId; @wire(...) @track |
| Functions and arrow functions | Event handlers, callbacks, array transformations | rows.filter(r => r.Amount > 10000) |
| Destructuring | Wire results, event data, Apex results | wiredContacts({ data, error }) { ... } |
| Spread operator | Copying read-only wire data, adding to arrays so the UI re-renders | this.items = [...this.items, newItem]; |
Array methods (map, filter, find, reduce) | Shaping Apex results for lightning-datatable or for:each | result.map(c => ({ ...c, url: '/' + c.Id })) |
| Template literals | Labels, URLs, CSS class strings | `${Name} (${Email})` |
| Promises and async/await | Imperative Apex calls, loadScript, record updates | const result = await getContacts(); |
| try/catch | Handling Apex errors and showing toasts | catch (error) { this.errorMessage = error.body.message; } |
| DOM events | onclick, onchange handlers, event.target, dataset | event.target.value |
CustomEvent | Sending data from a child component to its parent | new CustomEvent('select', { detail: { id } }) |
| Truthy and falsy values | lwc:if conditions in the template | <template lwc:if={hasContacts}> |
That's the whole list. It's a solid chunk of modern JavaScript, but it's finite, and none of it is Salesforce-specific. You can practise all of it in a browser console before you open an org.
How each concept plays out in a real component
Properties and reactivity
Class fields hold component state. When you assign a new value to a field the template uses, LWC re-renders. That's why you write this.searchKey = event.target.value and the screen updates.
There's one catch that trips up beginners. When a field holds an object or array, LWC notices when you assign a new one, but it doesn't notice when you change something inside the existing one, unless you decorate the field with @track. In practice, most developers skip @track and assign a new array with spread:
// Does not re-render without @track
this.items.push(newItem);
// Re-renders
this.items = [...this.items, newItem];
If spread syntax is new to you, learn it before LWC. You'll use it every day.
Public properties with @api
@api marks a property that a parent component, a Lightning page or Flow can set. @api recordId is how a component on a record page finds out which record it's on. You need to know what a class field is and what a decorator looks like. You don't need to know how decorators work under the hood.
Event handling
Template handlers are plain class methods:
<lightning-input label="Search" onchange={handleSearchChange}></lightning-input>
handleSearchChange(event) {
this.searchKey = event.target.value;
}
To use these comfortably you need DOM event basics: what event.target and event.currentTarget are, and how data-* attributes end up in event.currentTarget.dataset.
Going from child to parent means dispatching a CustomEvent with a detail payload. The parent listens with on plus the event name (oncontactselect={handleContactSelect}). If you've used addEventListener in plain JavaScript, this will feel familiar.
Wire adapters
@wire connects a property or function to Salesforce data and re-runs when its reactive parameters change. A $ prefix marks a parameter as reactive:
import { LightningElement, api, wire } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import NAME_FIELD from '@salesforce/schema/Account.Name';
export default class AccountHeader extends LightningElement {
@api recordId;
@wire(getRecord, { recordId: '$recordId', fields: [NAME_FIELD] })
account;
get name() {
return getFieldValue(this.account.data, NAME_FIELD);
}
}
Wiring to a function uses destructuring in the parameter list:
@wire(getContacts, { accountId: '$recordId' })
wiredContacts({ data, error }) {
if (data) {
this.contacts = data.map(c => ({ ...c, recordUrl: `/${c.Id}` }));
} else if (error) {
this.errorMessage = error.body?.message;
}
}
Data that comes back from a wire is read-only. That's why the example copies each record with { ...c } before adding a field. Without spread and destructuring, wire code is hard to read. The Salesforce Casts blog has worked examples of wiring an Apex method to a function.
Imperative Apex calls
When you need to call Apex on a button click, you import the method and call it. It returns a promise:
// Promise chain
getContacts({ accountId: this.recordId })
.then(result => { this.contacts = result; })
.catch(error => { this.errorMessage = error.body.message; });
// Same thing with async/await
async handleLoad() {
try {
this.contacts = await getContacts({ accountId: this.recordId });
} catch (error) {
this.errorMessage = error.body.message;
}
}
You should be able to read both styles, because real codebases mix them. See invoking an Apex method imperatively in LWC for a full walkthrough.
What you can skip
Many admins put off LWC because they assume they need the whole front-end stack first. You don't need any of these:
- Node.js and npm knowledge. You may install Node later to run Jest tests or Prettier, but you won't write Node code. Components deploy through the Salesforce CLI or VS Code extensions.
- Bundlers and build tools. No webpack, Vite or Babel config. The platform compiles your components.
- React, Angular or Vue. Experience with these helps a little, but LWC follows web standards (custom elements, shadow DOM, ES modules), so plain JavaScript transfers more directly.
- jQuery and heavy DOM manipulation. You rarely touch the DOM directly. When you do, it's
this.template.querySelector(...)inside your own component. - TypeScript, generators, prototype chains, event loop internals. You need to know that
awaitpauses the function until the promise settles. You don't need to explain microtask queues.
Traps for Apex developers and admins
These cause most of the confusion in a first LWC project:
- JavaScript is case-sensitive. Apex isn't. In Apex,
contact.nameandcontact.Nameare the same field. In JavaScript, an Apex result'sresult.nameisundefined. You must match the API name exactly:result.Name. thisinside callbacks. A regularfunctionpassed tosetTimeoutor.then()loses the component'sthis. An arrow function keeps it. This is the main practical reason arrow functions matter in LWC.===vs==. Use===. Loose equality turns'0' == 0intotrue, which hides bugs.nullvsundefined. A field you never set isundefined. A field Apex returns empty may be missing from the JSON altogether. Optional chaining (error?.body?.message) guards against both.- Mutating wire data. Trying to change a wired record throws an error. Copy it first.
Self-check: are you ready for LWC?
See how many of these you can do without looking anything up. Use a browser console or any online JavaScript playground.
- Explain why
const list = []; list.push(1);works butconst list = []; list = [1];fails. - Given an array of opportunity objects, return only those with
Amount > 10000, then turn them into strings like"Acme: 25000"usingfilter,mapand a template literal. - Destructure
dataanderrorfrom an object in a single line, then do the same inside a function's parameter list. - Write a class with one field, one getter and one method that changes the field using
this. - Explain the difference between
export defaultand a named export, and write the matchingimportfor each. - Rewrite a
.then().catch()chain as anasyncfunction withtry/catch. - Predict what
thisis inside asetTimeoutcallback written as afunction, and as an arrow function. - Copy an object with spread and change one property without touching the original.
- Attach a click listener to a button and log
event.targetand adata-idvalue. - Say whether
0,'',[]andnullare truthy or falsy.
If you can do eight or more, start LWC now and fill the gaps as you go. If you get fewer than six, spend focused time on JavaScript first. Items 3, 6 and 7 are the ones that most often separate people who get stuck in LWC from people who don't.
A practical learning order
For admins moving into development and developers new to the Salesforce UI, this order avoids the most frustration:
- Core JavaScript, in a Salesforce context. The free JavaScript for Lightning Web Components course on Salesforce Casts covers this in 22 episodes, 2.6 hours in total. It teaches the JavaScript you'll actually meet in components, with no detour into general web development. Watch an episode, then reproduce the code yourself before you move on.
- Your first components. A greeting component with an input bound to a property. Then a component that shows a record's fields with
getRecord. Then a parent and child that talk through a custom event. - Apex for LWC. Most real components call Apex. If you're an admin, learn enough Apex to write a
@AuraEnabled(cacheable=true)method that runs a SOQL query. The Salesforce Developer Roadmap shows where this fits next to everything else. - Structured LWC practice. Data tables, navigation, Lightning Message Service, error handling, Jest tests.
Salesforce Casts' Lightning Web Components Development course covers step 4. Like every course on the site, it's taught by Teja, an ex-engineer at Salesforce.com, and built live in a real org line by line, with no slide decks and no copy-paste code. Every course has a GitHub repo with the source code. Questions go to a private discussion group rather than live classes or 1:1 mentoring. The JavaScript course is free. Every paid plan unlocks the full catalogue of 20 courses, including the LWC course; plans are listed on the pricing page.
FAQ
Can I learn LWC without knowing JavaScript?
You can follow along with tutorials, but you'll stall as soon as you need to change something. Every behaviour in a component lives in the JavaScript file, and the template can't hold logic. Learning core JavaScript first is faster overall than debugging code you don't understand.
Do I need to learn Aura before LWC?
No. LWC is the current model for new Salesforce UI work, and it doesn't build on Aura concepts. You'll only need Aura if you maintain older orgs or have to embed an LWC inside an existing Aura component.
Do I need Node.js or npm to build Lightning Web Components?
Not to write or deploy them. You build components in VS Code with the Salesforce extensions and deploy with the Salesforce CLI. Node comes up later for running Jest unit tests locally, and even then you're running commands, not writing Node code.
How long does it take to learn enough JavaScript for LWC?
The free JavaScript for LWC course is 2.6 hours of video, but plan to spend several times that typing out the examples and working through the self-check list above. Developers who already write Apex usually move faster, because classes, methods and exceptions carry over.
Do I need to know Apex before LWC?
For simple components that use Lightning Data Service (getRecord, lightning-record-form), no. For anything that runs custom queries or business logic, yes: you'll write small @AuraEnabled Apex methods. Many people learn basic Apex and LWC side by side.
Is TypeScript required for LWC?
No. Standard LWC development uses plain modern JavaScript. Learn JavaScript first. TypeScript is optional and you can pick it up later if your team uses it.
Next step
Work through the ten self-check items tonight. If any of them stumped you, start the free JavaScript for Lightning Web Components course and build your first component as soon as you finish it.
Learn it by building it
Every course, every code repository, the discussion group and certificates of completion โ one subscription.
Keep going
Blog
How to use Optional Chaining in LWC
Blog
Preventing Memory Leaks in JavaScript: Best Practices with Code Examples
Blog
How to use if .. else if in LWC?
Blog
How to create multiple records using the createRecord method in LDS?
Blog
Copy to Clipboard functionality in LWC
Blog
How to download the current webpage in PDF format in LWC?