Overview
ThehelloExpressions component demonstrates how to use JavaScript expressions in Lightning Web Components templates. It shows how getters can compute derived values from component properties, enabling dynamic data transformation and formatting.
What It Does
This component accepts first and last name inputs from the user and displays the full name in uppercase. It uses a getter method (uppercasedFullName) to compute the uppercased full name from the firstName and lastName properties, demonstrating how to use JavaScript expressions in templates.
Component Code
Key Concepts
- Getters: The
get uppercasedFullName()method computes a derived value from properties - Template Expressions: Getters can be used in templates like regular properties
- Field Identification: The
event.target.nameattribute identifies which field triggered the event - String Manipulation: JavaScript string methods (template literals, trim, toUpperCase) transform the data
- Reactive Updates: When
firstNameorlastNamechanges, the getter automatically re-evaluates
How It Works
- User types in the “First Name” or “Last Name” input field
- The
handleChangemethod identifies which field changed usingevent.target.name - The corresponding property (
firstNameorlastName) is updated - The
uppercasedFullNamegetter combines and transforms the values - The template displays the computed uppercase full name
Usage Example
To use this component in your Salesforce org:- First Name: “John”
- Last Name: “Doe”
