{"id":2635,"date":"2026-11-15T13:00:00","date_gmt":"2026-11-15T07:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/?p=2635"},"modified":"2026-11-22T11:31:07","modified_gmt":"2026-11-22T06:01:07","slug":"lwc-advanced-interview-questions","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/","title":{"rendered":"LWC Advanced Interview Questions: Shadow DOM and Security"},"content":{"rendered":"\r\n<p class=\"wp-block-paragraph\">LWC Advanced Interview Questions move past decorators into the things that break at the worst moment. The shadow boundary, the security sandbox and third party libraries account for most of them.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Last reviewed for the Winter &#8217;27 release (November 2026).<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">This post covers what gets asked, grouped into shadow DOM and light DOM, Lightning Web Security, static resources and libraries, dynamic components and styling, and scenario questions where something will not render.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-advanced-interview-questions-diagram-1-1024x640.png\" alt=\"LWC Advanced Interview Questions diagram showing what the shadow boundary blocks\" class=\"wp-image-2633\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-advanced-interview-questions-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-advanced-interview-questions-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-advanced-interview-questions-diagram-1-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Caption: Styles, queries and events all behave differently because of that boundary.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">What LWC Advanced Interview Questions Cover<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">LWC Advanced Interview Questions start from the shadow boundary, because it explains four separate behaviours at once. Your markup sits under a shadow root, so page CSS cannot reach in and your queries cannot reach out.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Think of it like a hotel room. The corridor cannot rearrange your furniture, and you cannot borrow a lamp from the corridor.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The other half of LWC Advanced Interview Questions is the sandbox your JavaScript runs inside, which decides whether an outside library works at all.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">The Boundary Rules Worth Memorising<\/h2>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\"><table><thead><tr><th>Behaviour<\/th><th>What it means<\/th><\/tr><\/thead><tbody><tr><td>this.template.querySelector<\/td><td>Searches inside your component only<\/td><\/tr><tr><td>document.querySelector<\/td><td>Returns null for your markup<\/td><\/tr><tr><td>this.refs<\/td><td>A named handle, safer than a class selector<\/td><\/tr><tr><td>Page CSS<\/td><td>Cannot style your internals<\/td><\/tr><tr><td>Custom properties<\/td><td>The supported way to let a parent style you<\/td><\/tr><tr><td>Event retargeting<\/td><td>The parent sees the host element as the target<\/td><\/tr><\/tbody><\/table><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Those six rows answer a surprising number of LWC Advanced Interview Questions on their own.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>import { LightningElement } from 'lwc';\r\n\r\nexport default class ChartPanel extends LightningElement {\r\n  ready = false;\r\n\r\n  renderedCallback() {\r\n    if (this.ready) {\r\n      return;\r\n    }\r\n    this.ready = true;\r\n    const canvas = this.template.querySelector('canvas');\r\n    this.draw(canvas);\r\n  }\r\n}<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">That guard flag is the detail LWC Advanced Interview Questions look for, because renderedCallback runs after every render.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Shadow DOM vs Light DOM<\/h2>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-advanced-interview-questions-diagram-2-1024x640.png\" alt=\"LWC Advanced Interview Questions comparison of shadow DOM and light DOM\" class=\"wp-image-2634\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-advanced-interview-questions-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-advanced-interview-questions-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-advanced-interview-questions-diagram-2-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Caption: Light DOM trades the protection for access, so pick it only when a tool needs the access.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\"><table><thead><tr><th>Need<\/th><th>Pick<\/th><\/tr><\/thead><tbody><tr><td>A component in a managed package<\/td><td>Shadow DOM<\/td><\/tr><tr><td>An accessibility tool must read the markup<\/td><td>Light DOM<\/td><\/tr><tr><td>A third party script must attach to elements<\/td><td>Light DOM<\/td><\/tr><tr><td>Styling from a site stylesheet<\/td><td>Light DOM, or a custom property<\/td><\/tr><tr><td>Internals that will change<\/td><td>Shadow DOM<\/td><\/tr><\/tbody><\/table><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">LWC Advanced Interview Questions often finish by asking you to justify one of those rows.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The posts on <a href=\"https:\/\/swapnilzambare.com\/blog\/lwc-shadow-dom-vs-light-dom\/\">shadow DOM and light DOM<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/lightning-web-security-vs-locker\/\">Lightning Web Security<\/a> cover both areas, and <a href=\"https:\/\/swapnilzambare.com\/blog\/lwc-static-resources-libraries\/\">static resources<\/a> covers loading libraries.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">LWC Advanced Interview Questions on Shadow DOM<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q1: What is shadow DOM in one sentence?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A boundary around a component&#8217;s markup that <a href=\"https:\/\/swapnilzambare.com\/blog\/lwc-shadow-dom-vs-light-dom\/\">stops styles and DOM queries crossing<\/a> in either direction.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Your CSS cannot leak out and change other components, and page CSS cannot reach in and break yours.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: say both directions: styles cannot leak out, and outside code cannot reach in.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q2: Why does this.template exist?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Because the markup sits inside a shadow root, and this.template is the handle on that root.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">So you find elements with this.template.querySelector(&#8216;.total&#8217;), not document.querySelector.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q3: What does document.querySelector return for your elements?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">null, because your elements are inside a shadow root, not in the page&#8217;s main tree.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">That is by design: other code on the page cannot reach into your component.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: How do you find elements from a parent? You cannot query a child&#8217;s internals; ask the child through an @api method.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q4: What is synthetic shadow?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A JavaScript version of shadow DOM that LWC used to support browsers without the native feature.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It imitates the boundary but is less strict, so some leaks still work under it.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q5: What is native shadow?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The real browser feature, which is faster and stricter than the synthetic version.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Salesforce is moving components to native shadow DOM, so code should not depend on synthetic shadow behaviour.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q6: Why test with native shadow on?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Code that reaches across the boundary often works under synthetic shadow and fails under native shadow.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Testing early catches selectors and styles that will break when native shadow is turned on.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: mention Salesforce&#8217;s move to native shadow. It shows you follow the roadmap.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q7: How do you style the component wrapper?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">With the :host selector in the component&#8217;s CSS file.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: :host { display: block; margin-bottom: 1rem; } styles the component&#8217;s own outer element.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Can :host take a condition? Yes, :host(.active) styles the host when it has the active class.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q8: How does a parent change a colour inside a child?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The child exposes a CSS custom property, and the parent sets its value.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: the child uses color: var(&#8211;card-accent, #0176d3); and the parent sets c-card { &#8211;card-accent: #2e844a; }. Base components expose <a href=\"https:\/\/swapnilzambare.com\/blog\/slds-styling-hooks-lwc-css\/\">styling hooks<\/a> like &#8211;slds-c-button-brand-color-background the same way.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: name styling hooks. They are the supported way and interviewers expect the term.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q9: Why not override the child&#8217;s selectors?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Internal class names are not a public contract, so an override can break in any release.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Styling hooks and custom properties are the supported way to change how a component looks.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q10: What is light DOM?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A render mode where the component&#8217;s markup goes into the page tree with no shadow boundary.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Global CSS and outside scripts can reach the markup, which some third party libraries need.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Do slots work in light DOM? Yes, light DOM components support slots.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q11: How do you switch to it?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Set static renderMode = &#8216;light&#8217;; in the class and lwc:render-mode=&#8221;light&#8221; on the template tag.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Both are needed for the component to render without a shadow root.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: say both parts are needed. Many candidates forget the template attribute.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q12: What breaks if you set the field but not the attribute?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The component still renders in a shadow root, so the change seems to do nothing.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The template attribute and the class field must agree.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q13: What changes in your JavaScript under light DOM?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Queries use this.querySelector instead of this.template.querySelector.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">There is no shadow root, so the component itself is the starting point.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q14: Does light DOM remove your component&#8217;s own CSS scoping?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Your stylesheet is still scoped to the component if you name it with .scoped.css, but page rules can now reach your elements too.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Without scoping, your styles can also affect the rest of the page, so be careful with global selectors.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: How do you scope light DOM styles? Name the file componentName.scoped.css.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q15: Can a shadow component contain a light component?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes. Render mode is chosen per component.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A shadow component can hold a light DOM child, and the child&#8217;s markup sits inside the parent&#8217;s shadow tree.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q16: How does the boundary affect accessibility?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">An ARIA reference like aria-labelledby cannot point across the boundary, so keep a label and its input in the same component.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Base components handle this for you, which is one more reason to use them.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q17: What is a scoped stylesheet in a light DOM component?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A CSS file named componentName.scoped.css. In light DOM, it keeps the component&#8217;s styles from leaking to the rest of the page, while page styles can still reach the component.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q18: Why do base components like lightning-input not accept your CSS?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">They render inside their own shadow roots, so your selectors cannot reach their internal elements. Use the styling hooks each base component documents, or the SLDS design tokens.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q19: Where do you see the boundary in the browser?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The inspector shows a shadow root node above your markup.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">In Chrome DevTools, the Elements panel shows #shadow-root above the component&#8217;s markup. Expand it to inspect what is inside.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">LWC Advanced Interview Questions on Lightning Web Security<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q20: What is Lightning Web Security?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A JavaScript <a href=\"https:\/\/swapnilzambare.com\/blog\/lightning-web-security-vs-locker\/\">sandbox per namespace<\/a> that stops components on a page reading or changing each other&#8217;s data.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It isolates components using standard browser features, while letting each one work with real DOM objects.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: &#8220;sandbox per namespace&#8221; is the phrase that shows you understand it.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q21: What did it replace?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Lightning Locker, which wrapped DOM objects in secure proxies.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Locker is still supported, but Salesforce recommends Lightning Web Security for new and existing orgs.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Can you turn Locker back on? Yes, by unticking the Lightning Web Security setting.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q22: What is the main difference?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Locker wrapped objects in proxies. Lightning Web Security keeps objects real and changes only a few risky browser APIs.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Point<\/th><th>Lightning Locker<\/th><th>Lightning Web Security<\/th><\/tr><\/thead><tbody><tr><td>Isolation<\/td><td>Secure proxy wrappers<\/td><td>Sandbox per namespace<\/td><\/tr><tr><td>DOM objects<\/td><td>Wrapped, so some libraries break<\/td><td>Real objects<\/td><\/tr><tr><td>Third party libraries<\/td><td>Many need changes<\/td><td>Most work as written<\/td><\/tr><tr><td>Performance<\/td><td>Slower<\/td><td>Faster<\/td><\/tr><tr><td>Status<\/td><td>Older model<\/td><td>Recommended<\/td><\/tr><\/tbody><\/table><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: name the practical win: most third party libraries now work as written.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q23: What is a distortion?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A deliberate change to a browser API so code cannot misuse it across namespaces.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: access to document.cookie and some window properties is restricted, so one component cannot read another&#8217;s session data.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q24: Give three examples.<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Restricted access to document.cookie, limits on reaching outside your sandbox through window, and storage that is separated by namespace.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The exact list is in Salesforce&#8217;s Lightning Web Security documentation, and the console shows a message when a distortion blocks something.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q25: Why do outside libraries work better now?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">They get real DOM objects, so type checks and DOM traversal behave normally.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Under Locker, a library checking element instanceof HTMLElement could fail because of the proxy.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Which libraries benefited most? Charting and UI libraries like Chart.js and D3.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q26: Where is it switched on?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">In Setup, Session Settings, with the option to use Lightning Web Security for Lightning web components and Aura components.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Turn it on in a sandbox first and test every page that uses third party libraries.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q27: Is it on by default?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes in newer orgs. Older orgs may still be on Locker and need to switch it on.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Check Session Settings in each org rather than assuming.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q28: Does it cover Aura components?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes. Lightning Web Security covers Aura components too, so test Aura code when you change the setting.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Aura code that relied on Locker&#8217;s proxies or globals may behave differently.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q29: Why can one component not see a global another component loaded?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Each namespace has its own sandbox with its own globals.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A library loaded in one namespace&#8217;s component is not visible as a global to components from another namespace.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: connect this to the jQuery plugin scenario. Interviewers often ask both.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q30: What is the fix for a plugin that needs its core library?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Load the library and the plugin in the same component.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: await loadScript(this, jquery); await loadScript(this, jqueryPlugin); in one component, so both share the same sandbox.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q31: What replaces a shared browser storage key?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A record or a custom setting that every component reads the same way.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Browser storage is partitioned by namespace, so shared keys are not reliable.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q32: How do you check whether Lightning Web Security is on?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Open Setup, Session Settings, and look for the Lightning Web Security option. In code, there is no public API to check it, so test behaviour in each org.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q33: Does Lightning Web Security affect Apex?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">No. It runs in the browser and isolates JavaScript. Apex security, like sharing and CRUD checks, is a separate layer you still handle on the server.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q34: Will a green Jest suite prove the switch is safe?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">No. <a href=\"https:\/\/swapnilzambare.com\/blog\/lwc-jest-testing-sfdx-lwc-jest\/\">Jest runs outside<\/a> the browser sandbox, so add a manual pass.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Jest runs in Node with a simulated DOM, so test pages with real libraries in a sandbox org after switching the setting.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">LWC Advanced Interview Questions on Libraries and Dynamic Components<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q35: Can a component load a script from a public CDN?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">No. Scripts must live in your org as a static resource and be <a href=\"https:\/\/swapnilzambare.com\/blog\/lwc-static-resources-libraries\/\">loaded with loadScript<\/a>.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">That keeps the code reviewed, versioned and safe from changes on someone else&#8217;s server.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: say why: reviewed, versioned code that cannot change under you.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q36: Which module loads a script or a stylesheet?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">lightning\/platformResourceLoader, with loadScript and loadStyle.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: import { loadScript, loadStyle } from &#8216;lightning\/platformResourceLoader&#8217;; import CHART from &#8216;@salesforce\/resourceUrl\/chartjs&#8217;;<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Does loadScript load a file twice? No, it skips files already loaded in that namespace.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q37: Where should that load run?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">In renderedCallback when the library needs an element, with a guard flag so it runs once.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">If the library does not need the DOM, connectedCallback is fine.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q38: Why await the load?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Because the global the library creates does not exist until the file has run.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: await loadScript(this, CHART); then new window.Chart(canvas, config);<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q39: How do you load a core file and a plugin in order?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Await the core first, then await the plugin.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: await loadScript(this, LIB); await loadScript(this, LIB_PLUGIN); so the plugin finds its core.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q40: How do you load two independent files faster?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Load them together with Promise.all.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: await Promise.all([loadScript(this, LIB_A), loadStyle(this, LIB_A_CSS)]); saves time when the files do not depend on each other.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: mention Promise.all for independent files. It shows care for load time.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q41: How do you store a library with many files?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Zip the folder, upload it as one static resource, and add the inner path to the URL.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: loadScript(this, KIT + &#8216;\/dist\/kit.min.js&#8217;), where KIT is the resource URL.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q42: What is a dynamic component?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A component whose class is chosen at run time instead of written in the template.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: show a different editor component for each record type, without listing every one in the markup.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q43: Which directive renders one?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">&lt;lwc:component <a href=\"https:\/\/swapnilzambare.com\/blog\/lwc-dynamic-components\/\">lwc:is={componentCtor}<\/a>&gt;&lt;\/lwc:component&gt;.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Set componentCtor in JavaScript after importing the component you want.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: What must be enabled? lightning__dynamicComponent capability in the js-meta.xml.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q44: What does lwc:is expect?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A component constructor, from the default export of a dynamic import.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: const { default: ctor } = await import(&#8216;c\/onlineCourseEditor&#8217;); this.componentCtor = ctor;<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q45: Why keep a map of import calls?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">So the build knows every bundle that can be loaded, and an unknown key fails with a clear error.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: const EDITORS = { Online: () =&gt; import(&#8216;c\/onlineEditor&#8217;), Classroom: () =&gt; import(&#8216;c\/classroomEditor&#8217;) };<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q46: What is the main benefit?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Only the chosen component is downloaded, which keeps the first load small.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">On a page with many possible panels, users download only what they actually open.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: name lazy loading and bundle size. Those are the real benefits.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q47: When is a conditional template better?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">With two or three options, where plain markup is clearer than the extra indirection.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Point<\/th><th>lwc:if blocks<\/th><th>Dynamic component<\/th><\/tr><\/thead><tbody><tr><td>Number of options<\/td><td>A few<\/td><td>Many, or unknown ahead<\/td><\/tr><tr><td>Download<\/td><td>All included<\/td><td>Only the chosen one<\/td><\/tr><tr><td>Readability<\/td><td>Very clear<\/td><td>Needs a map of imports<\/td><\/tr><tr><td>Setup<\/td><td>None<\/td><td>Dynamic import must be enabled for the component<\/td><\/tr><\/tbody><\/table><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q48: What is a custom property editor?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A component that <a href=\"https:\/\/swapnilzambare.com\/blog\/lwc-custom-property-editor\/\">replaces the default property panel<\/a> for a custom flow screen component or action in Flow Builder.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It lets you build a friendlier setup screen, like dropdowns and validation, for admins using your component.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q49: How do you load a library only when the user needs it?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Call loadScript inside the click handler or after lwc:if shows the area, instead of in renderedCallback on page load. The first open is a little slower, but every page load is faster.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q50: What is Content Security Policy in Lightning?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Browser rules that limit which sites a page can load scripts, styles and connections from. Admins add allowed sites under CSP Trusted Sites, for example for an image CDN or an API your component calls with fetch.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q51: Which event does it fire?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A fixed configuration editor value changed event, with bubbles and composed set to true.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The event name is configuration_editor_input_value_changed, and its detail holds the property name, the new value and its data type.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Scenario Based LWC Advanced Interview Questions<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q52: Scenario: a page stylesheet styles your button and nothing changes. Why?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The button is behind the shadow boundary, so page CSS cannot reach it. Use a styling hook or custom property, or light DOM if you really need global styles.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">For lightning-button, set hooks like &#8211;slds-c-button-brand-color-background on a parent element.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q53: Scenario: a chart library draws nothing. What do you check?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Whether the canvas exists yet, and whether the library load was awaited in renderedCallback.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Query the canvas with this.template.querySelector after render, and draw only after await loadScript finishes.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q54: Scenario: the library loads ten times. What is missing?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A guard flag, because renderedCallback runs after every render.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Set this.libLoaded = true the first time and return early afterwards.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q55: Scenario: a plugin reports that jQuery is undefined. Why?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It was loaded by a component in another namespace, and each namespace has its own globals.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Load jQuery and the plugin in the same component, in order.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q56: Scenario: code worked under Locker and fails now. Where do you look?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The browser console, for a blocked API, a distortion message or a library that depended on Locker&#8217;s behaviour.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Test the library in a small component on its own, then check the Lightning Web Security distortion list for the API it uses.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q57: Scenario: an analytics tool cannot read your component. What is the trade off?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Light DOM would give the tool access, but it also removes the shadow protection, so decide on purpose.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Often the better choice is to send the data the tool needs through its own API, instead of letting it read your markup.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q58: Scenario: a test passed before a render mode change and fails now. Why?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The test&#8217;s selectors assume one render mode. Query through the component&#8217;s root in a way that works for the mode you use.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">In Jest, use element.shadowRoot.querySelector for shadow components and element.querySelector for light DOM ones.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q59: Scenario: a file path 404s in one org only. What changed?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The zip was rebuilt with a different top folder, so the path inside it changed. Open the resource URL and compare.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Keep the folder structure fixed in your build, and reference files with the same inner path everywhere.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q60: Scenario: a dynamic component shows nothing with no console error. Why?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A name string was passed to lwc:is instead of the component constructor.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Pass the default export from the dynamic import, not the component&#8217;s name.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: this is a classic silent bug. Say &#8220;constructor, not name&#8221; clearly.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q61: Scenario: switching dynamic options is slow every time. What do you fix?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Cache the constructor after the first import.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Keep a Map from option to constructor, and only call import() for options you have not loaded yet.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q62: Scenario: a custom property editor never saves a value. What is wrong?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The event is missing bubbles and composed, or the detail keys are wrong.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Dispatch configuration_editor_input_value_changed with bubbles: true, composed: true, and detail with name, newValue and newValueDataType.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q63: Scenario: a styling change broke after a release. What caused it?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">An override of internal selectors instead of a styling hook.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Replace it with the documented styling hooks for that base component, which Salesforce keeps stable between releases.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q64: Scenario: a third party date picker opens behind a modal. What do you check?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The z-index of the picker and the modal, and whether the picker renders into document.body, outside your shadow root, where the modal covers it. Many libraries have an option to render into a container element you choose.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q65: Scenario: a component is slow on a mobile device. What do you look at?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Large lists rendered at once, heavy libraries loaded on start, and too many server calls. Page or virtualise lists, load libraries only when needed, and combine Apex calls.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q66: Scenario: an interviewer asks when you would choose light DOM. What is a good answer?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Only when a named tool or library needs the open markup, and never as a styling shortcut.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Good answer: only when a named tool or library needs open markup, and never as a styling shortcut, because styling hooks solve that without giving up protection.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Common Mistakes Candidates Make<\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Using document.querySelector for their own markup, the first thing LWC Advanced Interview Questions catch<\/li>\r\n\r\n<li>Loading a library without awaiting it<\/li>\r\n\r\n<li>Forgetting the guard flag in renderedCallback<\/li>\r\n\r\n<li>Assuming a global loaded elsewhere will be visible<\/li>\r\n\r\n<li>Overriding internal selectors instead of using styling hooks<\/li>\r\n\r\n<li>Treating light DOM as a styling shortcut<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">More LWC Advanced Interview Questions<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q67: What does lwc:spread do?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It passes every property in an object to a child component at once, which keeps markup short when a child takes many public properties.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Can lwc:spread set event handlers? Yes, keys like onclick in the object become handlers.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q68: What replaced if:true and if:false?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The lwc:if, lwc:elseif and lwc:else directives. They are clearer and support more than two branches.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q69: What is a slot?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A placeholder in a child template where the parent can pass its own markup. Named slots let a parent fill several areas, such as a header and a footer.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q70: What is the render method used for?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It lets a component choose which HTML template to show at run time, by importing several templates and returning one.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q71: What is a mixin in LWC?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A function that adds behaviour to a class. <a href=\"https:\/\/swapnilzambare.com\/blog\/lwc-navigation-toasts-modals\/\">NavigationMixin<\/a> is the common example, used by extending NavigationMixin(LightningElement).<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q72: What is the GraphQL wire adapter for?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It reads related data from several objects in <a href=\"https:\/\/swapnilzambare.com\/blog\/graphql-wire-adapter-lwc\/\">one request through the UI API<\/a>, which can replace several separate wire calls.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q73: How does a headless quick action work?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The component exposes a <a href=\"https:\/\/swapnilzambare.com\/blog\/lwc-headless-quick-actions\/\">public invoke method<\/a> and has no markup. Salesforce calls invoke when the user clicks the action.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q74: How do you build a modal today?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Extend LightningModal from lightning\/modal and open it with the open method, which returns a promise with the result when it closes.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: How do you pass data into the modal? As properties in MyModal.open({ size: &#8216;small&#8217;, course: c }).<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q75: What is TypeScript support in LWC?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">You can write component code in TypeScript and compile it to JavaScript, with type definitions for LWC modules. It catches type mistakes during development, which helps large teams.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q76: How do you make a component work offline in the mobile app?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use the offline features of the Salesforce mobile app with LDS based data access, and design for cached data with clear messages when the device is offline. Components that use Apex directly do not work offline.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q77: How do you stop a search box calling Apex on every keystroke?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/swapnilzambare.com\/blog\/lwc-performance-best-practices\/\">Debounce it<\/a>. Wait a short time after the last key press before calling Apex, and cancel the earlier timer each time the user types.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: clearTimeout(this.timer); this.timer = setTimeout(() =&gt; this.search(term), 300); so Apex is called once the user pauses.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Best Practices to Mention in an Interview<\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Query with this.refs, and this.template as the fallback<\/li>\r\n\r\n<li>Expose CSS custom properties for anything a parent may restyle<\/li>\r\n\r\n<li>Guard anything in renderedCallback that should run once<\/li>\r\n\r\n<li>Load a library and its plugins in the same component<\/li>\r\n\r\n<li>Test with native shadow enabled before you trust it<\/li>\r\n\r\n<li>Cache dynamic component constructors after the first import<\/li>\r\n\r\n<li>Keep internals private, and treat the public surface as the contract<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/platform\/lwc\/guide\/\" target=\"_blank\" rel=\"noopener noreferrer\">Lightning Web Components Developer Guide<\/a><\/li>\r\n\r\n<li><a href=\"https:\/\/github.com\/trailheadapps\/lwc-recipes\" target=\"_blank\" rel=\"noopener noreferrer\">Lightning Web Components Recipes<\/a><\/li>\r\n\r\n<li><a href=\"https:\/\/trailhead.salesforce.com\/content\/learn\/modules\/lightning-web-components-basics\" target=\"_blank\" rel=\"noopener noreferrer\">Lightning Web Components Basics on Trailhead<\/a><\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>LWC Advanced Interview Questions start and end with the shadow boundary<\/li>\r\n\r\n<li>this.template and this.refs search inside, and document searches outside<\/li>\r\n\r\n<li>Light DOM trades protection for access, declared in two places<\/li>\r\n\r\n<li>The security sandbox is per namespace, so globals are not shared<\/li>\r\n\r\n<li>Libraries come from static resources, loaded and awaited with a guard<\/li>\r\n\r\n<li>Styling hooks survive upgrades, and selector overrides do not<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">What Is Next<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Coming soon: Jest testing interview questions for Lightning components.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>LWC Advanced Interview Questions with answers on shadow DOM, light DOM, Lightning Web Security, static resources, dynamic components and styling hooks.<\/p>\n","protected":false},"author":1,"featured_media":2632,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[250,8,90],"tags":[68,91,113,17],"swapz_series":[],"class_list":["post-2635","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developer-interview-questions","category-salesforce","category-salesforce-interview","tag-advanced","tag-interview-questions","tag-lwc","tag-security"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>LWC Advanced Interview Questions and Answers<\/title>\n<meta name=\"description\" content=\"LWC Advanced Interview Questions with answers on shadow DOM, light DOM, Lightning Web Security, static resources, dynamic components and styling hooks.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LWC Advanced Interview Questions and Answers\" \/>\n<meta property=\"og:description\" content=\"LWC Advanced Interview Questions with answers on shadow DOM, light DOM, Lightning Web Security, static resources, dynamic components and styling hooks.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-15T07:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-22T06:01:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-advanced-interview-questions-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"20 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-advanced-interview-questions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-advanced-interview-questions\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\"},\"headline\":\"LWC Advanced Interview Questions: Shadow DOM and Security\",\"datePublished\":\"2026-11-15T07:30:00+00:00\",\"dateModified\":\"2026-11-22T06:01:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-advanced-interview-questions\\\/\"},\"wordCount\":4015,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-advanced-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/lwc-advanced-interview-questions-featured.png\",\"keywords\":[\"Advanced\",\"Interview Questions\",\"LWC\",\"Security\"],\"articleSection\":[\"Developer Interview Questions\",\"Salesforce\",\"Salesforce Interview\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-advanced-interview-questions\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-advanced-interview-questions\\\/\",\"name\":\"LWC Advanced Interview Questions and Answers\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-advanced-interview-questions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-advanced-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/lwc-advanced-interview-questions-featured.png\",\"datePublished\":\"2026-11-15T07:30:00+00:00\",\"dateModified\":\"2026-11-22T06:01:07+00:00\",\"description\":\"LWC Advanced Interview Questions with answers on shadow DOM, light DOM, Lightning Web Security, static resources, dynamic components and styling hooks.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-advanced-interview-questions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-advanced-interview-questions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-advanced-interview-questions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/lwc-advanced-interview-questions-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/lwc-advanced-interview-questions-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"LWC Advanced Interview Questions featured image with sample question cards\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/lwc-advanced-interview-questions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"LWC Advanced Interview Questions: Shadow DOM and Security\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"LWC Advanced Interview Questions and Answers","description":"LWC Advanced Interview Questions with answers on shadow DOM, light DOM, Lightning Web Security, static resources, dynamic components and styling hooks.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/","og_locale":"en_US","og_type":"article","og_title":"LWC Advanced Interview Questions and Answers","og_description":"LWC Advanced Interview Questions with answers on shadow DOM, light DOM, Lightning Web Security, static resources, dynamic components and styling hooks.","og_url":"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-11-15T07:30:00+00:00","article_modified_time":"2026-11-22T06:01:07+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-advanced-interview-questions-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"20 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a"},"headline":"LWC Advanced Interview Questions: Shadow DOM and Security","datePublished":"2026-11-15T07:30:00+00:00","dateModified":"2026-11-22T06:01:07+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/"},"wordCount":4015,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-advanced-interview-questions-featured.png","keywords":["Advanced","Interview Questions","LWC","Security"],"articleSection":["Developer Interview Questions","Salesforce","Salesforce Interview"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/","url":"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/","name":"LWC Advanced Interview Questions and Answers","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-advanced-interview-questions-featured.png","datePublished":"2026-11-15T07:30:00+00:00","dateModified":"2026-11-22T06:01:07+00:00","description":"LWC Advanced Interview Questions with answers on shadow DOM, light DOM, Lightning Web Security, static resources, dynamic components and styling hooks.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-advanced-interview-questions-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/lwc-advanced-interview-questions-featured.png","width":2400,"height":1260,"caption":"LWC Advanced Interview Questions featured image with sample question cards"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/lwc-advanced-interview-questions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"LWC Advanced Interview Questions: Shadow DOM and Security"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=2635"}],"version-history":[{"count":3,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2635\/revisions"}],"predecessor-version":[{"id":3526,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2635\/revisions\/3526"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/2632"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=2635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=2635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=2635"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=2635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}