Reputation: 2808
Im learning javascript using webtools of essential webbrowsers (toolset with F12). here is a show up example
function sayHello(n){
document.writeln($`Hello {n}`);
}
sayHello("Andy Anderson");
//undefined appears as a result.
I expected result as "Hello Andy Anderson" but I got an undefined
Upvotes: 0
Views: 92
Reputation: 12139
The dollar sign comes before the opening curly brace:
document.writeln(`Hello ${n}`);
function sayHello(n){
document.writeln(`Hello ${n}`);
}
sayHello("Andy Anderson");
Upvotes: 2
Reputation:
Dollar sign placement is odd. It should be in the string.
document.writeln(`Hello ${n}`);
The reason you didn't get an error was that the $
is likely defined as a function in your environment, so it was used as a "tag" for the template literal.
Upvotes: 3