I am writing the following code in my VS code editor.
let name="Sam";
const val = "I am $ {name}";
console.log(val);
when I display it in console it should display" I am Sam" .But it is printing "I am $ {name}"
I have added extention of "JS ES6" and "Live Server" I am a beginner and unable to understand what I am doing wrong.
You need to define it as a template string, replace the " with ` and for the variable you have to remove the space between $ and {
let name="Sam";
const myval = `I am ${name}`;
console.log(myval);
For advanced description see here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals