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?
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?
Tagged template literals call the function that precedes them, which in this case is join
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`,`)
(Always) Check MDN web docs for enlightenment: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join
The join() method creates and returns a new string by concatenating all of the elements in an array (...) separated by commas or a specified separator string.