Sunday, December 22, 2019

Salesforce Lightning Web Components Interview Questions

1) What is LWC(Lightning Web Components)?

As of now, we have built a lightning component using the "Aura Components model". we can also build a lightning component using the "Lightning Web Components model". Lightning Web Components are custom HTML elements build using the HTML Elements and modern Javascript. We can build components using any of the models and can place these components on the same lightning page.

For developing LWC we require  "Salesforce Extensions for Visual Studio Code" and for deploying LWC from an org we require "Salesforce CLI".

Aura Components make use of own custom component model, custom templates, custom components, etc while LWC is built on web standards and it makes use of web components, templates, custom elements which we have in web standards. Both the Aura component, LWC make use of Security, LDS and Base lightning components.

Important points to note:

1) Aura component and LWC can exist on the same lightning page.
2) Aura component can include LWC

2) What is Scratch org?

Scratch org is a disposable Salesforce org used for development and testing.
Scratch org can be created for a maximum of 30 days after which scratch org gets deactivated. The default duration for Scratch org is 7 days.

3) Explain the Lightning Web Component Bundle?

LWC bundle contains an HTML file, a JavaScript file, and a metadata configuration file
and these files are created once we create a Lightning web component.

We can also create a .css file for styling purpose and We can also create SVG file for the purpose of displaying icon.

4) How to render the HTML file conditionally?

If we want to render HTML conditionally we can make use of if:true={propertyName},if:false={propertyName} in nested template tag.

5) How to iterate over an array in HTML file?

We can make use of for:each directive and iterator directive.

for:each directive:

for:each directive is used to render an array. To render an array add the for:each directive to a nested template tag, for:item is used to access the current item, for:index is used to access the current index.

Iterator directive:

If you have the requirement to access the first and the last element in the list use the iterator directive.

A sample HTML file is as shown below.

.html file

    <b>for:each directive</b>
    <template for:each={students} for:item="item" for:index="index">
        <p key={}>
    <!--Iterator directive-->
    <b>Iterator directive</b>
    <template iterator:it={students}>
<li key={}>
<!--To access the first and the last element use {it.first} and {it.last}-->

6) What are the types of decorators in lightning web components?

We have 3 Decorators in Lightning Web Components.

1) @api
2) @track
3) @wire

7) Explain all three decorators in lightning web components?

Refer to the below link for an explanation.

How we can build Lightning web components?

It is always recommended to use Salesforce DX tools for developing Lightning web components however we can still use code editor to develop Lightning web components. 

Note: we cannot build LWC in the Developer Console.

9) How can we use Lightning web component with unsupported tool?

To use a Lightning web component with an unsupported experience or tool we can wrap it in an Aura component.

10) Which command is use to authorize a dev hub?

"SFDX: Authorize a Dev Hub"

11) How many scratch orgs we can create daily, and how many can be active at a given point?

Our "Dev Hub" org edition determines how many scratch orgs we can create daily, and how many can be active at a given point.

12) How many files are created by default when we create a Lightning Web Component?

Three files are created as below.

HTML file.
JavaScript file.
Meta configuration file.

13) What is the purpose of .css file and svg file in Lightning Web Component bundle?

 .css file is use for styling purpose and svg file is use for purpose of displaying icon.

14) What is the purpose of HTML file in Lightning Web Component bundle?

  1. The HTML file is enclosed within the <template> tags.
  2. It contains the component HTML.
Sample HTML file shown below,

    <h1> Some Text </h1>

15) What is the purpose of JavaScript file in Lightning Web Component bundle?

  1. The JavaScript file defines the behavior of HTML element present in HTML file.
  2. JavaScript files in Lightning web components are ES6 modules. By default, everything declared in a module is local—it’s scoped to the module.
  3. If we want to import a class, function, or variable declared in a module we use the import statement. 
  4. If we want to allow other code to use a class, function, or variable declared in a module we use the export statement.
  5. The core module in Lightning Web Components is lwc. The import statement imports LightningElement from the lwc module.

import { LightningElement } from 'lwc';

Here, LightningElement is a custom wrapper of the standard HTML element.

Extend LightningElement to create a JavaScript class for a Lightning web component. You can’t extend any other class to create a Lightning web component.

export default class MyComponent extends LightningElement {

    // Code


The JavaScript file can contain:

The component’s public API via public properties and methods annotated with @api.

Private properties

Event handlers

16) What is Meta configuration file in Lightning Web Component?

The Meta configuration file defines the metadata values for the components.

If we don’t include a configuration file for our component, we get an error similar to the following when we push your changes.
Cannot find Lightning Component Bundle <component_name>

17) Is it possible to use multiple html files in a Lightning Web Component?

Yes and for this we will need to create multiple HTML files in the component bundle and than Import them all and add a condition in the render() method to return the correct template.

18) How many style sheet can a component have?

Each component can have only one style sheet.

19) Can components share the style sheet?


20) Does the style of the component get lost or override when we use the component with its own style sheet in different context?

When we define a style sheet for a component in a component folder it is limited to that component only and this avoid loosing the style sheet of the component when we reuse this component in different contexts. This also avoid component style sheet getting override in other part of the page.

21) How to share CSS style sheet in Lightning Web Component?

1) If we want to share CSS style than we will need to create a module that contains only a CSS file and for this we will need to create a Lightning Web Component with only single CSS file as shown below.

How to share CSS style sheet in Lightning Web Component

2) After we create a module we can import the module into CSS file of any Lightning Web Component as shown below.

@import 'namespace/nameOfModule';


#lwc interview questions#lightning web components interview questions#salesforce lwc interview questions#salesforce lightning web components interview questions#lwc salesforce interview questions#interview questions on lwc#interview questions on lwc salesforce#lightning web components interview questions and answers#interview questions on lightning web components
#lwc interview questions in salesforce#lwc interview questions salesforce#lwc interview questions and answers


  1. Really Appreciable!
    You have shared very valuable information that people should recognise. Thank you for sharing such an informative post with us. I would like share my contribution, sharing with you all my Salesforce app specially for Salesforce admins and developers and saves their most of time in performing bulk operations such as Bulk object/field creation, updation, deletion, cloning, etc., which is also available on appexchange:
    Bulk Object Field Creator
    Appexchange Url

  2. Thanks you so much,more information

  3. Thaanks for youl r valuable information.... really helpful

  4. Very nice contained. I hope I get a job by reading this soon.