PD1 Developer Fundamentals 5 — Questions and Answers
Question 1: Which Lightning Web Component lifecycle hook fires after every render of the component, including the initial render?
- connectedCallback()
- renderedCallback() (Correct answer)
- disconnectedCallback()
- constructor()
Correct answer: renderedCallback()
renderedCallback() is called after every render cycle, both the initial render and subsequent re-renders due to property changes.
Question 2: In LWC, how does a child component pass data up to a parent component?
- By directly modifying a property on the parent component
- By dispatching a custom event that the parent listens to (Correct answer)
- By calling a public method on the parent using querySelector
- By updating a shared Apex controller variable
Correct answer: By dispatching a custom event that the parent listens to
Child components communicate upward by dispatching CustomEvent objects, which parent components handle using event listener syntax in the template.
Question 3: What is the purpose of the @api decorator in a Lightning Web Component?
- It marks a property as reactive and tracks changes internally
- It exposes a property or method as public, allowing parent components to set it (Correct answer)
- It connects the component to an Apex method
- It registers the component in the Lightning App Builder
Correct answer: It exposes a property or method as public, allowing parent components to set it
The @api decorator makes a property or method publicly accessible, allowing parent components or App Builder admins to pass values in.
Question 4: Which Aura component attribute enables two-way data binding between a component and its parent?
- {!v.attributeName} (Correct answer)
- {#v.attributeName}
- {$Label.c.labelName}
- {!c.methodName}
Correct answer: {!v.attributeName}
The {!v.attributeName} expression syntax in Aura enables two-way data binding between a component's view value provider and its template.
Question 5: A developer needs to call an Apex method from LWC that should NOT be cached. Which wire adapter approach is correct?
- Use @wire with cacheable=false in the @AuraEnabled annotation
- Use @AuraEnabled(cacheable=true) with imperative Apex call
- Use an imperative Apex call (import and call as a function) instead of @wire (Correct answer)
- Use @wire with a 'nocache' parameter in the component
Correct answer: Use an imperative Apex call (import and call as a function) instead of @wire
Imperative Apex calls always fetch fresh data from the server, while @wire is designed for cacheable methods and may return cached results.
Question 6: What is the correct way to reference a static resource in a Lightning Web Component JavaScript file?
- import myResource from '@salesforce/resourceUrl/MyResourceName' (Correct answer)
- import myResource from '@salesforce/staticResource/MyResourceName'
- const url = '/resource/MyResourceName'
- import myResource from 'c/staticResource'
Correct answer: import myResource from '@salesforce/resourceUrl/MyResourceName'
Static resources are imported in LWC using the @salesforce/resourceUrl scoped module import syntax.
Question 7: Which LWC feature allows a component to subscribe to messages published by other components without a direct parent-child relationship?
- Custom Events with bubbling
- Lightning Message Service (LMS) (Correct answer)
- Aura Application Events
- Platform Events via @wire
Correct answer: Lightning Message Service (LMS)
Lightning Message Service enables communication between components in different parts of the DOM (including Visualforce and Aura) via a named message channel.
Which Lightning Web Component lifecycle hook fires after every render of the component, including the initial render?