// Basic template literal `Hello World` // String interpolation `Hello ${name}!` `The answer is ${40 + 2}` // Multi-line template `This is a multi-line template literal` // Nested templates `Outer ${`Inner ${depth}`} text` // Complex expressions `User: ${user.firstName} ${user.lastName}` `Total: $${price * quantity}` `Status: ${isActive ? 'Active' : func("inactive")}` // With function calls `Result: ${calculate(x, y)}` `Length: ${str.length}` `Upper: ${text.toUpperCase()}` // Escaping `Line 1\nLine 2` `Tab\there` `Quote: \`nested\`` // Tagged templates html`
${content}
` css`.class { color: ${color}; }` gql`query { user(id: ${id}) { name } }` tmpl`heloo ${name()}` // Nested braces inside interpolations — stack-tracked brace depth so the // first `}` inside an inner object/block doesn't close the interpolation. `${fn({a: 1})}` `${{a: 1}}` `${{a: {b: 2}}}` `${function() { return 1; }}` `${() => ({key: val})}` `${obj.method({k: v}).b}`