Loading topic
...args) and are comfortable with ordinary template literals that use backticks and ${} substitutions.2 min read...values) and template literal syntax with ${}. The previous chapter showed that writing a tag in front of a template literal turns it into a function call. Here we look at the two kinds of argument that call receives and the rules that 2 min readArray.prototype.reduce, and the shape of a tag call from the previous chapter: strings holds the static parts, values holds the evaluated substitutions, and strings.length is always values.length + 1.2 min readstrings array and its substitution values. It also assumes you know common escape sequences such as \n, \t, and \u0041.2 min readstrings array and its values. It also assumes you know that each string part has a cooked form, strings[i], and a raw form, strings.raw[i]. String.raw is the one tag that JavaScript ships with. It joins the raw parts with the substi2 min readstrings array and its substitution values, and how to rebuild a string with reduce. Here we drop the assumption that the result has to be a string.2 min readstrings array and values, and how reduce interleaves them to rebuild output. Here we use that pattern to fix a real security problem.2 min readstrings array and values, and how reduce without an initial value interleaves them. Here you will use that same mechanism to build SQL queries that resist injection.2 min readstrings and ...values, and that you are comfortable with Map, WeakMap, and closures. It covers two guarantees the engine makes about the strings array. The array cannot be changed, and the same array is passed every time a given cal2 min readstrings array and its values, and that you know how this works for ordinary method calls in JavaScript. So far, the tag has always been a plain identifier such as html or sql. The grammar is looser than that. A tag can be any membe2 min readstrings array, and how cooked strings differ from raw ones (strings.raw). It covers a narrow rule from ES2018: what happens when a template contains a backslash sequence that is not a valid escape.2 min readstrings array and values, that tags can return any value, and that each call site gets one frozen strings array. Here you will see how three popular libraries build on those facts.2 min readhtml and sql tags from earlier chapters. It also assumes you know about cooked versus raw strings and about member tags. Tagged templates are a small feature, but a handful of mistakes come up again and again. Most of them happen because a tag lo2 min read