1

For some methods, modern JS allows template literals to be passed without using parens.

ie [1,2,3].join`+` //=> '1+2+3'

console.log, however, returns something unexpected.

console.log`hello,world` //=> ["hello,world", raw: Array(1)]

Why is an array returned here as the output of console.log?

jdjd
  • 11
  • 2
  • 3
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals - See "tagged template literals" – Andrew Li Dec 12 '17 at 01:09
  • Thanks -- any idea why returning an array is the preferred behavior for console.log? – jdjd Dec 12 '17 at 01:19
  • Not exactly sure, I can't seem to reproduce your result exactly. An array is being returned because tagged template literals are passed as arrays to the function, and I guess all template literals have the `raw` property indicating the raw string. – Andrew Li Dec 12 '17 at 01:43

1 Answers1

1

That's because you're working with Template Literals. The backtick stuff doesn't mean you can eschew parens willy-nilly.

Everspace
  • 382
  • 1
  • 3
  • 13