Reputation: 1069
am kind of novice to nodeJS and javascript, while trying to print a variable value, the variable isn't getting replaced by its value.
var a="World";
console.log("Hello ${a}");
am getting "Hello ${a}"
instead of "Hello World"
Upvotes: 0
Views: 453
Reputation: 174
you can use this , you need to put assigned variable(a) out of string "" or else it will considered as a string
var a="World";
console.log("Hello",a);
Upvotes: 0
Reputation: 3340
If you are using ES6 you can use template literals with placeholders (which you are trying to do it seems):
var a="World";
console.log(`Hello ${a}`);
Other option is the traditional way, concatenating strings with the +
operator:
var a="World";
console.log("Hello " + a);
Upvotes: 1
Reputation: 68635
You need to use `` instead of "" . For more see Interpolation in Javascript
var a="World";
console.log(`Hello ${a}`);
Upvotes: 2