Ron I Ron I - 1 year ago 125
Javascript Question

ES6 / ECMA6 template literals - not working

I wanted to try using template literals and it's not working. I am using Chrome v50.0.2 (and Jquery).


console.log('categoryName: ${this.categoryName}\ncategoryElements: ${this.categoryElements} ');


categoryElements: ${this.categoryElements}

Hoping the SO community can help me sort this out, thanks in advance!

Answer Source

You are using the wrong quotations marks. You need to use backticks (next to the 1 key) not single quotes.

Backticks are common in many programming languages, but may be new to JavaScript developers.


console.log(`categoryName: ${this.categoryName}\ncategoryElements: ${categoryElements} `) 


VM626:1 categoryName: name 
categoryElements: element

See: What is the usage of the backtick symbol (`) in JavaScript?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download