Skip to main content
InterviewHubPRO
Section Overview
Q316

Question 316 of 536

Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

59%
JavaScript & V8 Internals (536 Qs)•Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

What are nesting templates

junior LevelCode ExampleComponents

The nesting template is a feature supported within template literals syntax to allow inner backticks inside a placeholder ${ } within the template. For example, the below nesting template is used to display the icons based on user permissions whereas outer template checks for platform type,

javascript
  const iconStyles = `icon ${
    isMobilePlatform()
      ? ""
      : `icon-${user.isAuthorized ? "submit" : "disabled"}`
  }`;

You can write the above use case without nesting template features as well. However, the nesting template feature is more compact and readable.

javascript
  //Without nesting templates
  const iconStyles = `icon ${
    isMobilePlatform()
      ? ""
      : user.isAuthorized
      ? "icon-submit"
      : "icon-disabled"
  }`;