Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Named variable appearing as string

const sayHi = (name) => {
console.log('Hello there ${name}')
}

module.exports = sayHi

Here is what it looks like

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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 '

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading