Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a function without braces, but using template string in Node.js [duplicate]

A function in JS can be called in the very strange way:

[1,2,3].join``
 -> "123"

Could somebody explain how it works "under the hood" or provide a link to some explanations?

like image 575
Egor Vasilev Avatar asked Sep 22 '26 22:09

Egor Vasilev


2 Answers

Tagged template literals call the function that precedes them, which in this case is join

like image 96
Max Avatar answered Sep 24 '26 11:09

Max


It seems you are referring tagged templates which allow you to parse template literals with a function & first argument of a tag function is related to the expression. Here join is the tag function

console.log([1,2,3].join`,`)
like image 20
brk Avatar answered Sep 24 '26 11:09

brk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!