DEV Community

Discussion on: JavaScript Template Literals

Collapse
 
moopet profile image
Ben Sinclair

That's not what I get when using the second one:

// Functions inside expressions

function func() { return I am the result of foo }
console.log(`bar ${func} baz.`);

// => bar function func() { return "I am the result of foo" } baz

console.log(`bar ${func()} baz.`);

// => bar I am the result of foo baz

I was thinking from your example that javascript does something clever to understand that a function is callable, but it doesn't - instead it returns the entire function definition as a string.