LWC
1. What is LWC and what files make up its structure?
LWC (Lightning Web Component) is built using 4 files:
HTML for the layout/markup
JS for all the logic
CSS for styling
XML (meta file) for configuration like where the component should appear in the app.
2. What is LWC and how is it different from Aura?
LWC uses modern standard web tech (HTML, JS, CSS) and is faster and simpler to learn. Aura is Salesforce's older proprietary framework. LWC has better performance and follows real web standards, while Aura requires learning Salesforce-specific patterns.
3. What is Salesforce Lightning and the Lightning Component Framework?
Salesforce Lightning is a component-based development framework for building Salesforce apps.
The Lightning Component Framework specifically lets developers build dynamic UIs for both desktop and mobile. Common components include Lightning Button, Input, Combo Box, etc.
4. What are the 3 decorators in LWC and what does each one do?
@api — makes a property public so parent components can pass data into it.
@track — makes a property (especially arrays/objects) fully reactive so that deep changes trigger re-rendering.
@wire — connects your component directly to Salesforce data or an Apex method automatically.
5. What are the 3 ways to communicate between LWC components?
1. Parent → Child: using @api to pass data down.
2. Child → Parent: using custom events dispatched from the child and caught by the parent.
3. Unrelated components: using Lightning Message Service (LMS).
6. How do you send data from a parent component to a child component?
In the child, mark a property with @api. Then in the parent's HTML, pass the value as an attribute using kebab-case.
Example:
<!-- child JS -->
@api messageFromParent
<!-- parent HTML -->
<c-child-comp message-from-parent={message}></c-child-comp>
7. How do you send data from a child component to a parent?
The child fires a CustomEvent with data in the detail field. The parent listens using on + eventName on the child tag.
Example:
<!-- child JS -->
const evt = new CustomEvent('send', { detail: this.value });
this.dispatchEvent(evt);
<!-- parent HTML -->
<c-child-comp onsend={handleFromChild}></c-child-comp>
8. What is a Promise in JavaScript and what are its states?
A Promise is an object that represents work happening in the background (asynchronously).
It has 3 states:
• Pending — still working
• Fulfilled — finished successfully
• Rejected — something went wrong
Use .then() for success and .catch() for errors.
9. What are the two ways to call an Apex method from LWC?
1. Wire (@wire): Data loads automatically and is cached. Good for fetching data. The Apex method must have @AuraEnabled(cacheable=true). Cannot be used for DML.
2. Imperative: You call the method yourself (e.g., on button click). Returns a promise. Useful for DML operations or controlled execution.
10. What are the lifecycle hooks in LWC and in what order do they run?
Lifecycle hooks let you run code at specific moments:
1. constructor() — component is created
2. connectedCallback() — component is added to the page
3. renderedCallback() — component has rendered on screen
4. disconnectedCallback() — component is removed
5. errorCallback() — a child component threw an error
11. How does conditional rendering work in LWC?
Use template directives to show/hide content based on a condition.
Modern LWC uses lwc:if, lwc:elseif, and lwc:else.
Older code uses if:true/if:false.
Only the block whose condition is true gets shown.
12. What is the difference between for:each and map() in LWC?
for:each is used in the HTML template to loop over an array and display items.
map() is a JavaScript array method that creates a new array with modified values.
Use for:each for rendering lists, and map() in JS when you need to transform data.
13. What is event bubbling and event capturing in LWC?
When a child fires an event, it can travel upward through the component tree (bubbling) if you set bubbles: true and composed: true. This lets grandparent components also hear it. Capturing is the reverse — events travel downward from parent to child. Setting both bubbles and composed allows events to cross shadow DOM boundaries.
14. If a deployed component is not visible to users, how would you debug it?
Check these things in order:
1. Is <isExposed>true</isExposed> set in the XML?
2. Is the correct <target> defined for where you're placing it?
3. Does the user's profile have access to the Apex class used?
4. Is SOQL running in user mode? Does the user have record access?
5. Is the component assigned to the correct page layout or app?
15. How can you make a component property editable from the page builder (dynamic per page)?
In the .js-meta.xml file, define a <property> inside <targetConfigs>.
Give it a name, type, and default value. In the JS, mark that property with @api.
Now admins can set different values for that property on each page without changing code.
16. What is Lightning Message Service (LMS)?
LMS is a Salesforce feature that lets totally unrelated components talk to each other. It even works across different technologies — LWC, Aura, and Visualforce. One component publishes a message to a channel, and any other component subscribed to that channel receives it.
17. What is Lightning Data Service (LDS)?
LDS lets you read, create, update, or delete Salesforce records directly from your component — without writing any Apex at all. It's great for simple use cases. It also caches data, so multiple components on a page sharing the same record stay in sync.
18. What is the uiRecordApi module in LWC?
uiRecordApi is a built-in LWC module with JS methods to manage records without Apex. Includes: createRecord(), deleteRecord(), getFieldValue(), generateRecordInputForCreate(), and more.
19. What is the difference between Promise.all() and Promise.race()?
Promise.all() waits for all promises to finish and resolves only when every one of them succeeds (fails if any one fails).Promise.race() doesn't wait for all — it resolves or rejects as soon as the first promise settles, whichever is fastest.
20. What is the difference between shallow copy and deep copy of objects?
A shallow copy (like spread {...obj}) copies only the top-level values. Nested objects still point to the same reference — changing them affects the original.
A deep copy (like JSON.parse(JSON.stringify(obj))) copies everything independently. Changes to the copy never affect the original.
21. What does the reduce() function do in JavaScript?
reduce() goes through every item in an array and combines them into a single result. You provide a starting value and a function that says how to combine each item with the running total. Classic use: summing up numbers in an array.
💬 Community Chatter
Loading...Join the Community Discussion
Login to ask questions, share answers, and connect with other Salesforce professionals.