const sayHi = (name) => {
console.log('Hello there ${name}')
}
module.exports = sayHi
In the console.log function I am calling the variable name but it is picking it as a string. I am learning nodejs and i dont know why i am getting this problem. ps: There is a mistake with the screenshot in terms of the variable name but that is not the problem.
CodePudding user response:
Copied from here https://stackoverflow.com/a/32695337/10776298
With Node.js v4 , you can use ES6's Template strings
var my_name = 'John';
var s = `hello ${my_name}, how are you doing`;
console.log(s); // prints hello John, how are you doing
You need to wrap string within backtick `
instead of '