A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://eslint.org/docs/latest/rules/no-template-curly-in-string below:

no-template-curly-in-string - ESLint - Pluggable JavaScript Linter

no-template-curly-in-string

Disallow template literal placeholder syntax in regular strings

Table of Contents

ECMAScript 6 allows programmers to create strings containing variable or expressions using template literals, instead of string concatenation, by writing expressions like ${variable} between two backtick quotes (`). It can be easy to use the wrong quotes when wanting to use template literals, by writing "${variable}", and end up with the literal value "${variable}" instead of a string containing the value of the injected expressions.

Rule Details

This rule aims to warn when a regular string contains what looks like a template literal placeholder. It will warn when it finds a string containing the template literal placeholder (${something}) that uses either " or ' for the quotes.

Examples

Examples of incorrect code for this rule:

Open in Playground

"Hello ${name}!";
'Hello ${name}!';
"Time: ${12 * 60 * 60 * 1000}";

1
2
3
4

Examples of correct code for this rule:

Open in Playground

`Hello ${name}!`;
`Time: ${12 * 60 * 60 * 1000}`;

templateFunction`Hello ${name}`;

1
2
3
4
5

When Not To Use It

This rule should not be used in ES3/5 environments.

Version

This rule was introduced in ESLint v3.3.0.

Resources

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4