Interview Questions
1. What are Lightning Web Components (LWC)?
2. What is the file structure of Lightning Web Components?
- myComponent folder
- myComponent.html
- myComponent.js
- myComponent.js-meta.xml
- myComponent.css
- myComponent.svg
3. How can you display components HTML conditionally
With the help of if:true|false directive
4. How we can iterate list in Lightning Web Component (LWC)
With the help of for:each and Iterator directive
5. Can we render multiple templates based on condition?
Yes we can render multiple templates based on the render method.
Temp1.html
<template>
<p>
hello Temp-1,
</p>
<p>
this is the template One
</p>
<button onclick={handleToggleButton}>Change</button>
</template>
Temp2.html
<template>
<p>
hello Temp2,
</p>
<p>
this is the template Two
</p>
<button onclick={handleToggleButton}>Change</button>
</template>
import { LightningElement, track } from 'lwc';
import {default as mainTemplate} from './Temp1.html'
import {default as anotherTemplate} from './Temp2.html'
export default class Salesforcedriller extends LightningElement {
@track usetemp = false;
render() {
return this.usetemp ? mainTemplate : anotherTemplate;
}
handleToggleButtonPress() {
this.usetemp = !this.usetemp;
}
}
6. What are the public properties in Lightning Web Components?
@api is the public reactive property.
7. What are the types of decorators in lightning web components?
We have 3 Decorators in Lightning Web Components.
- @api
- @track
- @wire
8. 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.
9. Can components share the style sheet?
No.
10. How to pass data from child to parent?
With the help of custom events.
this.dispatchEvent(new CustomEvent(EventName));
11. Can we use aura and LWC simultaneously?
Aura can include LWC but LWC can not include Aura.
12. Best practices for lightning?
- Do not use so many Console.log
- Try to use LDS As much as possible
- limit number of event handlers in your Lightning component
- Caching the data at the client side.
- Don’t return a huge number of rows at once from backend
- Try to use limits in the query result.
- Try to minimize the column on the result set.
- Use @AuraEnabled(cacheable=true) to reduce the server call.
13. Is there any limit on how many components to have in one Application ?
There is no limit.
14. What is the template?
It is a reusable structure in the HTML page.
15. Which parts of Lightning Components are server-side and which are client-side ?
JavaScript on the client side and Apex on the server side.
