Computer >> Computer tutorials >  >> Programming >> Javascript

ES6/ECMA6 template literals not working in JavaScript?


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

Example

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.

Output

This will produce the following output −

PS C:\Users\Amit\javascript-code> node demo320.js
First Name is= John
Last Name is= Smith