--- id: javascript-string-templates title: "JavaScript String Templates" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["template strings", "template literals", "back-tics", "string interpolation", "ES6 strings"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.89 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "template-literals", "interpolation", "es6"] raw_sources: ["https://www.w3schools.com/js/js_string_templates.asp"] applied_in: [] github_commit: "" --- # [[JavaScript String Templates]] ## π― ν μ€ ν΅μ°° (One-line insight) Template strings use back-ticks instead of quotes, letting you embed both quote types, write multiline text, and interpolate variables and expressions with `${...}` β an ES6 feature supported in all modern browsers since June 2017. [S1] ## π§ ν΅μ¬ κ°λ (Core concepts) - **Back-tics define the string** β template strings use back-ticks (`` ` ``) rather than the quotes (`"`) to define a string. [S1] - **Both quote types allowed inside** β template strings allow both single and double quotes inside a string. [S1] - **Multiline strings** β template strings allow multiline strings. [S1] - **Interpolation** β template strings allow variables in strings using the `${...}` syntax. [S1] - **Expression substitution** β template strings allow interpolation of expressions in strings. [S1] - **ES6 feature** β template strings are an ES6 feature; ES6 is fully supported in all modern browsers since June 2017. [S1] ## π§© μΆμΆλ ν¨ν΄ (Extracted patterns) - **Interpolate variables** β drop variables straight into text with `${variable}` instead of concatenating with `+`. [S1] - **Interpolate expressions** β compute inline, e.g. `${(price * (1 + VAT)).toFixed(2)}`. [S1] - **Build HTML templates** β assemble HTML by interpolating values and looping to append list items. [S1] ## π μΈλΆ λ΄μ© (Details) **Back-Tics Syntax** Template strings use back-ticks (`` ` ``) rather than the quotes (`"`) to define a string. [S1] ```javascript let text = `Hello World!`; ``` **Quotes Inside Strings** Template strings allow both single and double quotes inside a string. [S1] ```javascript let text = `He's often called "Johnny"`; ``` **Multiline Strings** Template strings allow multiline strings. [S1] ```javascript let text = `The quick brown fox jumps over the lazy dog`; ``` **Interpolation** Template strings allow variables in strings, using the `${...}` interpolation syntax. [S1] ```javascript let firstName = "John"; let lastName = "Doe"; let text = `Welcome ${firstName}, ${lastName}!`; ``` **Expression Substitution** Template strings allow interpolation of expressions in strings. [S1] ```javascript let price = 10; let VAT = 0.25; let total = `Total: ${(price * (1 + VAT)).toFixed(2)}`; ``` **HTML Templates** Template strings can be used to build HTML by interpolating values and looping over data. [S1] ```javascript let header = "Template Strings"; let tags = ["template strings", "javascript", "es6"]; let html = `