2

Why are parentheses not needed in the following ES2015 code using a template literal?

['a', 'b'].join`|` // a|b
Ben Aston
  • 53,718
  • 65
  • 205
  • 331

1 Answers1

1

Pretty sure this is a "tagged template string". From the ES6 wiki:

Example: If a template string is preceded by an expression it is considered a tagged template string. The expression before the template string is called with the parsed template string.

function tag(strings, ...values) {
  assert(strings[0] === 'a');
  assert(strings[1] === 'b');
  assert(values[0] === 0);
  return 'whatever';
}
tag `a${ 42 }b`  // "whatever"
Tim Consolazio
  • 4,802
  • 2
  • 19
  • 28