Skip to content
UniCircle
EasyConceptualStrings

String immutability and template literals

Question JS-STR-001

Strings in JavaScript are immutable. What does that mean in practice? What are template literals and what can they do that quotes cannot?

Show the explanation

Model answer. Immutable means a string value can never be changed in place. Every "change" creates a new string:

JavaScript
let word = 'cat';
word[0] = 'b';            // silently ignored (TypeError in strict mode)
word = 'b' + word.slice(1);   // 'bat': a new string assigned to the variable

Methods like toUpperCase, replace and trim all return new strings; they never modify the original.

Template literals use backticks and add:

  • Interpolation: ` Total: ${qty * price} ` evaluates any expression.
  • Multi-line strings without \n.
  • Tagged templates: a function processes the parts, used by libraries for safe SQL, CSS-in-JS or translations.

Single and double quotes behave identically; pick one style. Use backticks whenever you insert values, rather than chaining +.

Original UniCircle question. Last reviewed 22 Oct 2026.