0

Is this a new way to call a function? Whats this even called? Why do this?

const foo = a => console.log(a)

const k = foo`stuff here?` //whaaaaaaa

//output is ["stuff here?"]
jason
  • 4,721
  • 8
  • 37
  • 45
  • 3
    I believe this is what you are looking for https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates. I too saw this syntax a while ago and didnt understand and after some searching found this. – Gowtham Raj J Mar 04 '21 at 19:22
  • I don't know who would downvote this. This isn't quite template literals, and even though I use it every week I don't actually know what it's called. It's a common pattern used in Styled-Components and Emotion. – Slbox Mar 04 '21 at 19:23
  • I guess the name is "Tagged templates" as per Gowtham's link. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates – Slbox Mar 04 '21 at 19:24
  • 6
    Does this answer your question? [Backticks calling a function](https://stackoverflow.com/questions/29660381/backticks-calling-a-function) – Phoenix Mar 04 '21 at 19:24

1 Answers1

1

they are called tagged template functions. You can read more on how they work and what they do here: MDN

Keimeno
  • 2,512
  • 1
  • 13
  • 34