LWC Interview Questions almost always start with the decorators, because they are the shortest way to find out whether someone has built components or only read about them. The follow up is usually about the lifecycle.
Last reviewed for the Winter ’27 release (November 2026).
This post covers the questions that get asked, grouped into the template, the decorators, lifecycle hooks, reactivity and getters, and scenario questions where a component is not updating.

Caption: The constructor has no DOM, and renderedCallback is the first hook that does.
What LWC Interview Questions Cover
LWC Interview Questions test whether you work with the framework or against it. LWC Interview Questions rest on one idea. A Lightning web component is three files, and the framework decides when to render.
Think of it like a thermostat. The hook order behind all of this is covered in the post on lifecycle hooks. You set the target and it decides when to act, rather than you switching the heating on by hand.
LWC Interview Questions often begin with the file layout. A bundle holds an HTML template, a JavaScript class and a metadata file, plus optional CSS and test files. The class name and the folder name must match.
The Files and the Tags
| File | What it holds |
|---|---|
| The html file | The template, with one root template tag |
| The js file | The class extending LightningElement |
| The js-meta.xml file | Exposure, targets and configurable properties |
| The css file | Styles scoped to the component |
| The test file | Jest tests, in a tests folder |
| Directive | What it does |
|---|---|
| lwc:if and lwc:else | Conditional rendering |
| for:each with for:item | Looping, with a key on each item |
| iterator:it | Looping with first and last flags |
| lwc:ref | A named handle to an element |
| slot | A place for a parent to put content |
import { LightningElement, api } from 'lwc';
export default class CourseCard extends LightningElement {
@api courseId;
@api fee = 0;
get formattedFee() {
return this.fee > 0 ? '₹' + this.fee : 'Free';
}
get isFree() {
return this.fee === 0;
}
}
Those getters are the pattern LWC Interview Questions reward. Templates cannot hold expressions, so anything computed belongs in a getter rather than in the markup.
api vs track vs wire

Caption: Fields are reactive by default, which is why track is rarely needed now.
| Question | Answer |
|---|---|
| Does a plain field re-render the template | Yes, when reassigned |
| When do you still need track | For deep changes inside an object or array |
| What makes a property settable by a parent | The api decorator |
| What makes a method callable by a parent | The api decorator on the method |
| What does wire do | Binds a property or function to a data source |
LWC Interview Questions tend to work through that table one row at a time.
The post on parent to child communication covers the api decorator in depth, and the post on wire adapters covers wire.
LWC Interview Questions on the Template
Q1: What must the root of a template be?
A single <template> tag.
Everything the component shows goes inside it. Nested template tags are used only for directives like lwc:if and for:each.
Follow-up you may get: Which other files does a component need? A JavaScript file and a js-meta.xml file.
Q2: Can you put an expression in markup?
No. Templates accept only property and getter references, so any calculation goes in a getter.
Example: instead of {price * qty}, write get total() { return this.price * this.qty; } and use {total} in the markup.
Interview tip: say “getters, not expressions”. It is the short answer interviewers want.
Q3: How do you render something conditionally?
With the lwc:if directive, plus lwc:elseif and lwc:else for the other branches.
Example: <template lwc:if={isLoading}><lightning-spinner></lightning-spinner></template><template lwc:else>…</template>
| Directive | What it does | Example |
|---|---|---|
| lwc:if / lwc:elseif / lwc:else | Shows one branch | lwc:if={hasRecords} |
| for:each with for:item | Loops over a list | for:each={courses} for:item=”c” |
| iterator:it | Loops with first and last flags | iterator:it={courses} |
| key | Identifies each looped item | key={c.Id} |
| lwc:ref | Names an element for this.refs | lwc:ref=”searchBox” |
Q4: What replaced the older if:true directive?
The lwc:if, lwc:elseif and lwc:else directives, which replaced if:true and if:false.
The older directives still work but are no longer recommended, and new code should use lwc:if, which is also slightly faster.
Interview tip: mention lwc:if is the current form. Using if:true in a whiteboard answer looks dated.
Q5: How do you loop over a list?
With for:each and for:item, or with iterator:it when you need first and last flags.
Example: <template for:each={courses} for:item=”c”><p key={c.Id}>{c.Name}</p></template>
Q6: Why does each item need a key?
So the framework can match items between renders and update only what changed.
Without a stable key, LWC may rebuild the whole list, which is slower and can lose input focus or state.
Follow-up you may get: Where does the key go? On the first element inside the loop template.
Q7: Can the key be the array index?
It should not be, because the index changes when items are added, removed or sorted.
Use a stable value like the record Id. With the index, a sort can make the wrong row keep the wrong state.
Interview tip: give the sorting example. It shows you know why keys matter.
Q8: What does iterator:it give you that for:each does not?
iterator.first and iterator.last flags, useful for separators and styling.
Example: inside iterator:it={courses}, put a divider in <template lwc:if={it.last}></template><template lwc:else><hr/></template> so it appears after every item except the last. Read the item itself from it.value.
Q9: What is a slot?
A placeholder in the child’s markup where the parent puts its own content.
Example: a card component has <slot></slot> in its body, and the parent writes <c-card><p>Any content</p></c-card>.
Q10: What is a named slot?
A slot with a name, so the parent can target a specific place.
Example: the child has <slot name=”footer”></slot>, and the parent writes <div slot=”footer”>Buttons</div>.
Follow-up you may get: Do slots work in light DOM? Yes, light DOM components support slots too.
Q11: How do you bind an attribute?
With curly braces around a property or getter name, without quotes.
Example: <lightning-input value={searchTerm}></lightning-input> binds the input’s value to the searchTerm field.
Q12: How do you handle an event in markup?
With on plus the event name, bound to a handler method.
Example: <lightning-button onclick={handleSave}></lightning-button> calls handleSave(event) when clicked.
Q13: Why is the handler name not called with parentheses?
Because you pass a reference to the function, and the framework calls it with the event.
Writing onclick={handleSave()} is not valid in LWC templates; the framework needs the function itself.
Interview tip: this is a common written test trap. Point it out.
Q14: How do you pass data to a handler from a loop?
With a data attribute on the element, read from event.currentTarget.dataset.
Example: <button data-id={c.Id} onclick={handleSelect}> then handleSelect(e) { const id = e.currentTarget.dataset.id; }
Follow-up you may get: Why currentTarget, not target? target can be a child element; currentTarget is the element with the handler.
Q15: Can a template have two root elements inside the template tag?
Yes. The single template tag can hold several sibling elements.
Only the outermost tag must be one <template>. Inside it, you can have a header, a list and a footer side by side.
Q16: What is lwc:ref?
A directive that names an element so you can reach it with this.refs instead of querySelector. Example: <lightning-input lwc:ref=”search”> and then this.refs.search.focus(). It is simpler and does not depend on CSS selectors.
Q17: How do you apply a CSS class conditionally?
Use a getter that returns the class string. Example: get rowClass() { return this.isActive ? ‘slds-theme_success’ : ‘slds-theme_default’; } and class={rowClass} in the markup.
Q18: How do you render raw HTML?
With lwc:dom=”manual” on an empty element and setting innerHTML in JavaScript, after sanitising. Avoid it where you can.
For rich text from records, lightning-formatted-rich-text is safer, because it removes unsafe tags for you.
LWC Interview Questions on Decorators
Q19: Which three decorators does LWC provide?
@api, @track and @wire.
@api makes something public, @track watches changes inside objects and arrays, and @wire connects to a data source.
Q20: What does api do on a property?
It makes the property public, so a parent component or a Lightning page can set it.
Example: @api recordId; on a record page receives the current record’s ID automatically.
Follow-up you may get: What naming does HTML use for recordId? Kebab case: record-id.
Q21: What does api do on a method?
It makes the method public, so a parent can call it through a reference to the child.
Example: in the child, @api reset() { … }; in the parent, this.refs.form.reset();
Q22: Should a child mutate an api property?
No. Data flows down, so the child should fire an event and let the parent change the value.
Treat @api values as read only inside the child. If the child needs its own copy, copy the value into a private field.
Interview tip: “data down, events up” is the phrase interviewers listen for.
Q23: Why are plain fields reactive?
Because LWC watches every class field and re-renders when a field gets a new value.
So this.count = this.count + 1 updates the template without any decorator.
Q24: When is track still needed?
When you change something inside an object or array, instead of assigning a new one.
Example: this.filters.level = ‘Advanced’ changes a property inside an object; without @track or a new object, the template does not update.
Interview tip: say you prefer new references over @track. It shows modern practice.
Q25: Give an example that needs track.
Pushing into an array held in a field, where the reference stays the same.
this.items.push(newItem) changes the array’s contents but not the field’s value, so an untracked field does not re-render.
Q26: What is the cleaner alternative to track?
Assign a new array or object, which the framework notices without @track.
Example: this.items = […this.items, newItem]; or this.filters = { …this.filters, level: ‘Advanced’ };
Q27: What does wire do?
It connects a property or function to a data source that pushes values to the component.
Example: @wire(getRecord, { recordId: ‘$recordId’, fields: FIELDS }) account; fetches the record and updates when recordId changes.
Follow-up you may get: Does wire run on the server or client? The adapter runs on the client and may call the server.
Q28: What is the difference between wiring a property and a function?
A wired property receives an object with data and error. A wired function receives that object as an argument, so you can process it.
Use a function when you need to transform the data or handle the error before storing it.
Q29: Can you wire a method with parameters?
Yes, with reactive parameters that start with a dollar sign.
Example: @wire(getCourses, { level: ‘$selectedLevel’ }) courses; runs again whenever selectedLevel changes.
Interview tip: always mention the $ prefix. Forgetting it is the most common wire bug.
Q30: What makes a wire refire?
A change in one of its reactive parameters, the ones prefixed with $.
If a parameter is undefined, the wire waits and does not call the server yet.
Q31: Why does a getter work better than a field for wire parameters?
A getter can return a new value built from several fields, and the wire sees the change.
Example: get filterKey() { return this.level + ‘|’ + this.city; } then ‘$filterKey’ in the wire.
Q32: Can you wire an Apex method?
Yes, if the method is @AuraEnabled(cacheable=true), which means it cannot do DML.
For saves, import the method and call it imperatively instead.
Follow-up you may get: How do you refresh wired Apex? refreshApex on the stored wired result.
Q33: What is the difference between @api, @track and @wire?
@api makes a property or method public for parents. @track watches changes inside objects and arrays. @wire connects a property or function to a data source like an Apex method or LDS. Most fields need none of them, because plain fields are reactive.
Q34: Can an @api property have a setter?
Yes. Use an @api getter and setter pair to react when the parent changes the value, like resetting a list when a filter changes. Store the value in a private field inside the setter.
Q35: What does api do for a value set in App Builder?
Combined with a property in the meta file, it lets an admin set it.
In the js-meta.xml, add a property inside targetConfig, like <property name=”title” type=”String” label=”Card title”/>, and match it with @api title in JavaScript.
LWC Interview Questions on Lifecycle Hooks
Q36: Name the lifecycle hooks in order.
constructor, connectedCallback, render, renderedCallback, disconnectedCallback, and errorCallback when a child throws.
| Hook | When it runs | Use it for |
|---|---|---|
| constructor | Component is created | Default values only; no DOM, no public properties yet |
| connectedCallback | Added to the page | Load data, subscribe to channels |
| renderedCallback | After every render | DOM work and libraries, with a guard flag |
| disconnectedCallback | Removed from the page | Unsubscribe, clear timers |
| errorCallback | A child throws | Show a friendly error |
Q37: What can you not do in the constructor?
Touch the DOM or read public properties, because neither is ready yet.
Call super() first, then only set default field values.
Interview tip: name both things that are not ready: DOM and public properties.
Q38: What is connectedCallback for?
Setup that does not need the DOM, like subscribing to a message channel or starting a data fetch.
Example: connectedCallback() { this.subscription = subscribe(this.messageContext, COURSE_CHANNEL, (m) => this.handle(m)); }
Q39: Are public properties available in connectedCallback?
Yes. Public properties set by the parent are available by then.
That is why loading data based on recordId usually happens in connectedCallback or a wire.
Q40: When does renderedCallback run?
After every render, so it can run many times.
Each time a tracked field changes and the template re-renders, renderedCallback runs again.
Follow-up you may get: Does renderedCallback run for children first? Yes, children finish rendering before the parent’s renderedCallback.
Q41: Why does that matter?
Work there needs a guard flag, or it repeats on every re-render.
Example: if (this.chartLoaded) return; this.chartLoaded = true; then load the chart library.
Interview tip: give the guard flag code in one line.
Q42: What is renderedCallback usually used for?
Reading the DOM, or loading a third party library that needs an element to exist.
Example: loadScript for a chart library, then drawing into a canvas element from the template.
Q43: What is disconnectedCallback for?
Clean up, like unsubscribing from message channels or clearing intervals.
Example: disconnectedCallback() { unsubscribe(this.subscription); clearInterval(this.timer); }
Q44: What happens if you skip that cleanup?
Subscriptions and timers keep running, which leaks memory and causes duplicate behaviour.
A user who opens the same record several times can end up with several timers polling the server.
Q45: What does errorCallback do?
It catches errors thrown by child components, so the parent can show a message instead of breaking.
Example: errorCallback(error, stack) { this.errorMessage = ‘Something went wrong loading this section.’; }
Interview tip: compare it with React error boundaries if you know React.
Q46: Where does errorCallback not help?
Errors in the component’s own code, which need their own try and catch.
errorCallback acts like an error boundary for children only.
Q47: What is the render method for?
Returning a different template, so one component can switch between layouts.
Example: import two HTML files and return mobileTemplate or desktopTemplate from render() based on form factor.
Q48: In which order do parent and child hooks run?
The parent’s constructor and connectedCallback run first, then the child’s. On render, the child’s renderedCallback runs before the parent’s, because the parent finishes rendering only after its children.
Q49: What are dynamic components in LWC?
Components created at run time with lwc:component and lwc:is, when you do not know which component to show until the code runs. Example: show a different editor component per record type, loading it with import() only when needed.
Q50: Is overriding render common?
No. It is for genuine two template cases, not everyday work.
Most components use one template and lwc:if blocks instead.
LWC Interview Questions on Reactivity and Getters
Q51: What triggers a re-render?
Assigning a new value to a field the template uses, or a change inside a tracked object.
Changes to fields the template does not use do not cause a re-render.
Q52: Does mutating an object property re-render?
Not unless the field uses @track or you assign a new object.
Example: this.course.name = ‘New’ on a plain field does nothing visible; this.course = { …this.course, name: ‘New’ } updates the page.
Q53: What is the safest habit with arrays?
Build a new array and assign it, instead of pushing into the existing one.
Examples: add with […this.items, x], remove with this.items.filter(i => i.id !== id), change with this.items.map(…).
Q54: Why are getters preferred over computed fields?
Getters recalculate automatically when the fields they use change, with no extra code to keep values in sync.
Example: get selectedCount() { return this.rows.filter(r => r.selected).length; } is always right, unlike a counter you must update by hand.
Follow-up you may get: Can a getter take parameters? No, use a method or precompute in a field.
Q55: Can a getter have side effects?
It should not, because it runs on every render.
A getter that changes fields or calls the server can cause loops and extra calls. Keep getters pure: read and return only.
Q56: Why is a query inside a getter a problem?
Getters run often, so anything slow inside them runs often too.
Load data once with a wire or in connectedCallback, and let getters only format or filter what is already there.
Q57: How do you format a currency value?
With lightning-formatted-number using format-style=”currency”, or in a getter with Intl.NumberFormat.
Example: <lightning-formatted-number value={fee} format-style=”currency” currency-code=”INR”></lightning-formatted-number> shows ₹15,000.00 in the user’s locale.
Q58: Where does component state belong?
In fields on the class, with getters for anything calculated from them.
Keep one source of truth per value. If two components need it, lift it to a shared parent or use Lightning Message Service.
Q59: How do you share state between unrelated components?
Lightning Message Service, or Lightning Data Service when they show the same record.
LDS keeps one cached copy of a record, so an edit in one component updates every component showing that record.
Q60: How do you make a component work in light DOM?
Add static renderMode = ‘light’; in the class and lwc:render-mode=”light” on the template. Global styles can then reach it, which helps with some libraries, but you lose shadow DOM style isolation.
Q61: What is TypeScript support in LWC?
You can write LWC JavaScript in TypeScript and compile it, which gives type checking for properties and methods. It catches mistakes earlier, especially in large teams.
Q62: Does browser storage work in a component?
It works in some contexts and not others, so platform state is the safer answer.
For data that must survive between sessions or devices, save it in Salesforce records instead of the browser.
Scenario Based LWC Interview Questions
Q63: Scenario: a list does not update after you push an item. Why?
The array was changed in place, so the field’s value stayed the same and the framework saw no change.
Assign a new array: this.items = […this.items, newItem];
Q64: Scenario: querySelector returns null in connectedCallback. Why?
The template has not rendered yet, so move the code to renderedCallback.
Also use this.template.querySelector, not document.querySelector, because each component’s DOM is isolated.
Q65: Scenario: a library loads ten times. What is missing?
A guard flag, because renderedCallback runs after every render.
Set a field like this.libLoaded = true the first time and return early after that.
Interview tip: connect this back to the lifecycle question about renderedCallback.
Q66: Scenario: a parent sets a property and the child ignores it. What do you check?
Whether the property has the @api decorator.
Also check the attribute name in the parent’s markup: a property called recordId is written record-id in HTML.
Q67: Scenario: a child changes an api property and the parent does not update. Why?
Data flows down, so the child must not change an @api value. It should fire an event instead.
The parent handles the event, updates its own field, and the new value flows back down to the child.
Q68: Scenario: a wire never refires when a filter changes. What is wrong?
The parameter is not reactive. Use a $ prefix, and a getter if it combines several fields.
Without the $, the wire reads the value once and never notices later changes.
Q69: Scenario: an Apex method cannot be wired. Why?
It is not cacheable=true, usually because it does DML.
Split it: a cacheable method for reading, and a separate method called imperatively for saving.
Q70: Scenario: a component works alone and breaks inside a parent. What do you suspect?
A public property the parent does not set, or CSS that assumes a certain container size.
Check which @api properties the component needs, give them defaults, and test it inside different parents and page regions.
Follow-up you may get: How do you test layouts quickly? Place it in different regions in Lightning App Builder and check mobile preview.
Q71: Scenario: after navigating away, a timer keeps firing. What is missing?
Clean up in disconnectedCallback: clear the interval and unsubscribe.
Example: disconnectedCallback() { clearInterval(this.pollTimer); }
Q72: Scenario: a child error takes down the page. What do you add?
An errorCallback in the parent that shows a friendly message.
Log the error too, and show a fallback view for that section so the rest of the page keeps working.
Q73: Scenario: a loop renders the wrong items after a sort. What caused it?
The key is the array index instead of a stable ID.
After sorting, the indexes match different items, so the framework reuses the wrong rows. Use key={item.Id}.
Q74: Scenario: a value shows as undefined on first render. Why?
The data has not arrived yet, so guard the template and show a spinner.
Example: <template lwc:if={courses.data}> … </template> and a lightning-spinner while it is loading.
Q75: Scenario: a component shows stale data after a record is edited elsewhere on the page. What do you check?
Whether it reads data through LDS or wired getRecord, which update automatically, or through a cached Apex method, which does not. For Apex, call refreshApex or notifyRecordUpdateAvailable after edits.
Q76: Scenario: a page with many components is slow. What do you look at first?
How many server calls happen on load, large lists rendered at once, and heavy work in renderedCallback or getters. Combine calls, use lazy loading with lwc:if, and page long lists.
Q77: Scenario: an interviewer asks for one habit that prevents most LWC bugs. What do you say?
Treat data as flowing down and events as flowing up, and never mutate a public property.
Treat data as flowing down through properties and events as flowing up, and never change a public property inside the child.
Common Mistakes Candidates Make
- Putting logic in the template instead of a getter, the first thing LWC Interview Questions check
- Mutating an object or array and expecting a re-render
- Reading the DOM in connectedCallback
- Forgetting that renderedCallback runs more than once
- Mutating an api property inside the child
- Using the array index as a loop key
Best Practices to Mention in an Interview
- Data down through properties, events up to the parent
- Everything computed in a getter, nothing in the markup
- Reassign arrays and objects rather than mutating them
- Guard anything in renderedCallback that should run once
- Clean up subscriptions and timers in disconnectedCallback
- Stable ids as loop keys, never the index
- A spinner and a guard for data that has not arrived
Official Resources
- Lightning Web Components Developer Guide
- Lightning Web Components Basics on Trailhead
- Lightning Web Components Recipes
Quick Recap
- LWC Interview Questions start with decorators and move to the lifecycle
- Templates hold references, and getters hold calculations
- Fields are reactive on reassignment, and track covers deep mutation
- api makes a property or method public to a parent
- renderedCallback is the first hook with a DOM, and it runs repeatedly
- Clean up in disconnectedCallback, every time
What Is Next
Coming soon: LWC data interview questions on wire, Apex and Lightning Data Service.


