Template literals

Template literals are text literals that allow for embedded expressions. They are enclosed by backtick characters instead of single or double quotes.

Use dark colors for code blocksCopy
1
2
`Hello World`
// returns "Hello World"

Template literals can embed quotes in a text value without having to escape.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
// message is defined with a template literal
var message = `My name is "Dave"`

// is equivalent to
message = "My name is \"Dave\"";

// throws an error - Parse Error: Unexpected identifier
message = "My name is "Dave"";

New lines are preserved without needing to use the TextFormatting.NewLine constant or \n.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var list = `Corn: 5,000
Wheat: 4,000
Rice: 2,000
Other: 500`;

// Output is the same as
list = "Corn: 5,000\nWheat: 4,000\nRice: 2,000\nOther: 500\n";

// and the same as
list = "Corn: 5,000\n" +
"Wheat: 4,000\n" +
"Rice: 2,000\n" +
"Other: 500\n";

// and the same as
list = "Corn: 5,000" + TextFormatting.NewLine
"Wheat: 4,000" + TextFormatting.NewLine
"Rice: 2,000" + TextFormatting.NewLine
"Other: 500" + TextFormatting.NewLine;

Template literals can contain placeholders for values and statements, indicated by a dollar sign and curly braces (${your_expression_here}). All expressions in placeholders within template literals are evaluated and inserted as a text literal. This allows for easier text manipulation in Arcade.

Use dark colors for code blocksCopy
1
2
`There are ${$feature.STUDENTS} students at ${$feature.UNIVERSITY}.`
// returns "There are 15,000 students at the University of California."
Use dark colors for code blocksCopy
1
2
3
var scores = [70, 85, 92, 98, 100, 78, 89];
`The average score was ${Round(Average(scores), 2)}%.`
// returns "The average score was 87.43%."

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.