“Vorlagenliterale” Code-Antworten

String -Interpolation JavaScript

const age = 3
console.log(`I'm ${age} years old!`)
Drab Dogfish

String buchstäblicher JavaScript

`string text`

`string text line 1
 string text line 2`

`string text ${expression} string text`

tag`string text ${expression} string text`
Happy Heron

JavaScript -Vorlage Literale

//Must use backticks, `, in order to work.

let a = 5;
let b = 10;
console.log(`Fifteen is ${a + b} and
not ${2 * a + b}.`);

//Output:
//Fifteen is 15 and not 20.
Blue-eyed Bee

Template Literal Syntax

`half of 100 is ${100 / 2}`
Crazy Cobra

Vorlage wörtliche Typen

/** A template literal produces a new string literal type by concatenating
    the contents. When a union is used in the interpolated position, the 
    type is the set of every possible string literal that could be 
    represented by each union member: */

type Taste = "Delicious" | "Spicy";
type Food = "Pizza" | "Meat";
 
type Menu = `${Taste | Food}`;

// Menu will now be one of the following:
// 'DeliciousPizza' | 'DeliciousMeat' | 'SpicyPizza' | 'SpicyMeat'
Stupid Scarab

Vorlagenliterale

let fourthItem = 'Item 4';
let myHtml = `
  <ol class="item-list">
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
    <li>${fourthItem}</li>
  </ol>
`;
Gorgeous Goldfinch

Ähnliche Antworten wie “Vorlagenliterale”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen