1. What is the purpose of Lightning Web Components (LWC)?

a) To enhance the performance of Salesforce Lightning Components

b) To provide a framework for building web applications

c) To enable developers to build reusable UI components for Salesforce applications

d) To replace Visualforce pages in Salesforce development


2. Which of the following statements about LWC is true?

a) LWC can only be used within Salesforce applications

b) LWC is based on the Aura framework

c) LWC provides a secure runtime environment

d) LWC is only compatible with Internet Explorer browsers


3. What is the recommended way to communicate between Lightning Web Components?

a) Using the window.postMessage() method

b) Utilizing the Lightning Message Service

c) Directly accessing the DOM elements of other components

d) Using global variables declared in JavaScript files


4. Which lifecycle hook is called when a Lightning Web Component is inserted into the DOM?

a) connectedCallback()

b) renderedCallback()

c) constructor()

d) disconnectedCallback()


5. How can you expose a public property in a Lightning Web Component?

a) By using the @api decorator in the JavaScript class

b) By defining it in the HTML template

c) By declaring it as a global variable

d) By using the public keyword in the JavaScript class


6. Which attribute is used to track the value of an input field in LWC?

a) value

b) data-value

c) input-value

d) text


7. In LWC, how can you conditionally render HTML based on a boolean property?

a) Using the if directive

b) Using the for:each directive

c) Using the bind directive

d) Using the class directive


8. What is the primary benefit of using Lightning Web Components over Aura Components?

a) Better performance and smaller bundle sizes

b) Greater compatibility with older browsers

c) More extensive built-in UI components

d) Easier integration with third-party libraries


9. Which decorator is used to create a property that reacts to data changes and re-renders the component?

a) @track

b) @reactive

c) @render

d) @observe


10. What is the recommended way to handle user input events in Lightning Web Components?

a) By directly modifying the DOM elements

b) By using imperative JavaScript calls

c) By declaring event handlers in the template and handling them in the JavaScript file

d) By using global event listeners

11. What is the file extension used for Lightning Web Components (LWC) JavaScript files?

a) .js

b) .lwc

c) .lwjs

d) .cmp.js


12. How can you import a custom JavaScript module into a Lightning Web Component?

a) Using the <script> tag in the HTML template

b) By directly referencing the JavaScript file in the component's metadata

c) By using the import statement in the JavaScript file

d) By including the JavaScript code directly in the component's JavaScript file


13. Which of the following is NOT a valid data type for a property in a Lightning Web Component?

a) String

b) Array

c) Object

d) Boolean


14. How can you iterate over a list of items in a Lightning Web Component template?

a) Using the <aura:iteration> tag

b) By using the for loop in the JavaScript file

c) Using the <template for:each> directive

d) By using the forEach() method in the JavaScript file


15. What is the purpose of the wire service in Lightning Web Components?

a) To connect the component to a network

b) To enable communication between components

c) To wirelessly transmit data between server and client

d) To fetch and cache data from a Salesforce org or external source


16. How can you pass data from a parent component to a child component in Lightning Web Components?

a) By directly modifying the child component's properties

b) By using the @track decorator in the parent component

c) By passing data through HTML attributes in the parent component's markup

d) By using the wire service to establish a data connection


17. Which JavaScript method is used to perform cleanup in a Lightning Web Component before it is removed from the DOM?

a) disconnectedCallback()

b) cleanup()

c) destroy()

d) remove()


18. How can you conditionally apply CSS classes in a Lightning Web Component?

a) By using the if:true directive in the HTML template

b) By directly modifying the class attribute in the HTML template

c) By using the class directive in the HTML template

d) By using the :class directive in the HTML template


19. What is the recommended way to handle errors in asynchronous operations in Lightning Web Components?

a) By using try-catch blocks in the JavaScript file

b) By ignoring errors since LWC handles them automatically

c) By using the .catch() method in Promises

d) By relying on Salesforce platform to handle errors automatically


20. How can you debug Lightning Web Components?

a) By using console.log() statements in JavaScript

b) By utilizing browser developer tools

c) By using the Salesforce Developer Console

d) All of the above



Answer Key:

1. c) To enable developers to build reusable UI components for Salesforce applications
2. c) LWC provides a secure runtime environment
3. b) Utilizing the Lightning Message Service
4. a) connectedCallback()
5. a) By using the @api decorator in the JavaScript class
6. a) value
7. a) Using the if directive
8. a) Better performance and smaller bundle sizes
9. a) @track
10. c) By declaring event handlers in the template and handling them in the JavaScript file
11. a) .js
12. c) By using the import statement in the JavaScript file
13. d) Boolean
14. c) Using the <template for:each> directive
15. d) To fetch and cache data from a Salesforce org or external source
16. c) By passing data through HTML attributes in the parent component's markup
17. a) disconnectedCallback()
18. d) By using the :class directive in the HTML template
19. c) By using the .catch() method in Promises
20.d) All of the above