Creating Strings in JavaScript
A string is an ordered sequence of characters used to represent text. JavaScript provides three distinct syntaxes for creating string literals, and understanding when to use each is fundamental to writing clean, readable code.
Single and Double Quotes
Single-quoted and double-quoted strings behave identically. The only practical difference is which quote character you must escape inside each. Use single quotes when your string contains double quotes, and vice versa.
'Hello, world!'— single-quoted"Hello, world!"— double-quoted- Escape a quote with a backslash:
'it\'s fine'
Template Literals
Template literals use backticks (`) and unlock two powerful features: multi-line strings without escape sequences, and embedded expressions via ${ } placeholders. Any valid JavaScript expression can appear inside the placeholder, including function calls and arithmetic.
String Immutability
Strings in JavaScript are immutable — once created, their characters cannot be changed in place. Operations that appear to modify a string actually return a new string, leaving the original untouched.