Search code examples
javascriptvisual-studio-codetemplate-strings

template strings not working


Template Strings should work on any terminals such as visual studio code terminal or windows terminal. But it didn't. I did this code visual studio code. Here is My code

var name = 'Andrew';
console.log('Hello ${name}');

and the output is

Hello ${name}

Please specify changes in my code needed and explain why it doesn't work currently.


Solution

  • Single and double quotes wont invoke the behavior - use back ticks.

    var name = 'Andrew';
    console.log(`Hello ${name}`);
    //          ^             ^

    More information on Template literals,