Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Salesforce Plat-Dev-301 Exam - Topic 3 Question 1 Discussion

Given the following containment hierarchy:HTMLWhat is the correct way to communicate the new value of a property named "passthrough" to my-parent-component if the property is defined within my-child-component?
C) let cEvent = new CustomEvent('passthrough', { detail: this.passthrough }); this.dispatchEvent(cEvent);
A) let cEvent = new CustomEvent('passthrough', { detail: 'this.passthrough' }); this.dispatchEvent(cEvent);
B) let cEvent = new CustomEvent('passthrough'); this.dispatchEvent(cEvent);
D) let cEvent = new CustomEvent($passthrough); this.dispatchEvent(cEvent);

Salesforce Plat-Dev-301 Exam - Topic 3 Question 1 Discussion

Actual exam question for Salesforce's Plat-Dev-301 exam
Question #: 1
Topic #: 3
[All Plat-Dev-301 Questions]

Given the following containment hierarchy:

HTML

What is the correct way to communicate the new value of a property named "passthrough" to my-parent-component if the property is defined within my-child-component?

Show Suggested Answer Hide Answer
Suggested Answer: C

In Lightning Web Components (LWC), data flows 'down' via properties and 'up' via events. When a child component needs to communicate a change in a property or state to its parent, it must dispatch a CustomEvent. To pass specific data---such as the new value of the passthrough property---along with the event, the developer must use the detail property within the event initialization object.

Option C is the correct syntax. It creates a new CustomEvent named 'passthrough' and assigns the current value of the component's property (this.passthrough) to the detail key. The parent component can then listen for this event (using onpassthrough={handleEvent}) and access the value via event.detail. Option A is incorrect because it wraps the variable in quotes, passing the literal string 'this.passthrough' instead of the actual data. Option B creates an event but fails to include the data payload, meaning the parent would know an event occurred but wouldn't receive the new value. Option D uses incorrect syntax for event naming and variable referencing. Using the standard CustomEvent constructor with the detail property is the platform-standard way to ensure robust, typed data communication between component layers in the Shadow DOM.

==========


Contribute your Thoughts:

0/2000 characters

Currently there are no comments in this discussion, be the first to comment!


Save Cancel