ES6/ECMA6 template literals not working in JavaScript?

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

In order to use template literals, you need to use backticks(` `) not single quotes(‘ ‘).


Following is the code −

var firstName="John";
var lastName="Smith";
console.log(`First Name is= ${firstName}\nLast Name is= ${lastName} `);

To run the above program, you need to use the below command −

node fileName.js.

Here, my file name is demo320.js.


This will produce the following output −

PS C:\Users\Amit\javascript-code> node demo320.js
First Name is= John
Last Name is= Smith
Updated on 26-Oct-2020 11:28:48