Home >Web Front-end >JS Tutorial >Why Aren't My JavaScript Template Literals Showing Dynamic Values?
Despite using template literals, you encounter an issue where the literal variable names are displayed instead of their values. To resolve this problem, ensure that you're using backticks (`), not quotation marks, to create template literals.
JavaScript template literals, also known as template strings, require backticks (`) to enclose the template. These backticks are located next to the 1 key on a QWERTY keyboard. Using single quotes (') or double quotes (") will not create the desired template literal.
Consider the following example:
categoryName = "name"; categoryElements = "element"; console.log(`categoryName: ${this.categoryName}\ncategoryElements: ${categoryElements} `);
categoryName: name categoryElements: element
Using backticks (), the template literal correctly interpolates the categoryName and categoryElements` variables, resulting in their respective values being displayed.
The above is the detailed content of Why Aren't My JavaScript Template Literals Showing Dynamic Values?. For more information, please follow other related articles on the PHP Chinese website!