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(‘ ‘).

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
raja
Published on 26-Oct-2020 15:58:35
Advertisements