pertrai1
pertrai1

Reputation: 4328

Invoke functions in es6 template literal?

I am trying to figure out how I can invoke functions inside of a template literal and don't seem to be able to get it to work. I am new to working with templates so there has to be something I am not aware of.

function test1(text) {
  return text;
}

function test2(text) {
  return text;
}

function finalTest() {
  console.log(`This is test1('hi there') and test2('hi again')`);
}

finalTest();

Upvotes: 2

Views: 424

Answers (2)

HBP
HBP

Reputation: 16063

As described here : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

You need to wrap your expressions in ${...}

Upvotes: 0

dfsq
dfsq

Reputation: 193301

Just put them in curly braces like any other expression you want to process as javascript:

console.log(`This is ${test1('hi there')} and ${test2('hi again')}`);

Upvotes: 1

Related Questions