JavaScript · Senior · Question 19 of 75
What does a tagged template do?
const q = sql`SELECT * FROM users WHERE id = ${id}`;- ✓Correct answer: Calls the
sqlfunction with an array of string parts and the substituted values - 2Compiles the string into a ready SQL query at build time
- 3Escapes all characters of the string for safe insertion into HTML
Explanation
The tag function receives strings and the values separately, so it can safely escape substitutions or pass them as query parameters - protection against injections. That's how styled-components, graphql tags and String.raw work.