ECMAScript template literals like 'some ${string}' are not working
Solution 1:
JavaScript template literals require backticks, not straight quotation marks.
You need to use backticks (otherwise known as "grave accents" - which you'll find next to the 1 key if you're using a QWERTY keyboard) - rather than single quotes - to create a template literal.
Backticks are common in many programming languages but may be new to JavaScript developers.
Example:categoryName="name";
categoryElements="element";
console.log(`categoryName: ${this.categoryName}\ncategoryElements: ${categoryElements} `)
Output:
VM626:1 categoryName: name
categoryElements: element
See:
Usage of the backtick character (`) in JavaScript
Solution 2:
There are three quotation marks, but just one entrance is working which we can use as TEMPLATE LITERALS:
-
" "
(é key on keyboard) is not working:
console.log("Server is running on port: ${PORT}")
-
' '
(Shift + 2 key on keyboard) is not working:
console.log('Server is running on port: ${PORT}')
-
` `
(Alt + Num96 key on keyboard) is working:
console.log(`Server is running on port: ${PORT}`)
Solution 3:
it only works if you use backpacks, on my Mac Pro that is ` which is above the tab key.
If you use single or double quotes it won't work!