user310291
user310291

Reputation: 38238

ES6 Template strings: how to nest them?

I'd like to nest them like this but I get error. Is there a way ?

let greetings1 = 'hello1';
let greetings2 = 'hello2';

let template1 = ``${greetings1}``;
let template2 = ``${greetings2}``;

let template = `${template1}`;
console.log(template);

Upvotes: 0

Views: 41

Answers (2)

sonEtLumiere
sonEtLumiere

Reputation: 4572

The problem is the double quotation marks

let greetings1 = 'hello1';
let greetings2 = 'hello2';

let template1 = `${greetings1}`;
let template2 = `${greetings2}`;

let template = `${template1}`;
console.log(template);

Upvotes: 1

Daniel García
Daniel García

Reputation: 46

I hope this helps.

let greetings1 = 'hello1';
let greetings2 = 'hello2';

let template = `${greetings1} ${greetings2}`;

console.log(template);

Upvotes: 1

Related Questions