When attempting to utilize JavaScript template literals such as some ${string} or "some ${string}", users may encounter problems where the literal variable names are displayed rather than their values. This issue is not limited to specific browser versions or development frameworks like jQuery.
To rectify this issue, it is crucial to employ backticks (`) instead of the conventional single or double quotation marks. Backticks, commonly referred to as "grave accents," are situated next to the numeral 1 key on standard QWERTY keyboards.
Example:
// Incorrect approach console.log('categoryName: ${this.categoryName}\ncategoryElements: ${this.categoryElements} '); // Correct approach using backticks console.log(`categoryName: ${this.categoryName}\ncategoryElements: ${this.categoryElements} `);
By using backticks, you can correctly invoke template literals and display the desired variable values.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3