Strings
easyComplete guide with examples and interview questions · 25 min
Say it out loud in an interview — clear, simple, no textbook wording.
If someone asks what a string is in JavaScript, I'd say it's how the language stores text — user names, error messages, JSON payloads, all of it. You create them with single quotes, double quotes, or backticks for templates.
Interviewers almost always follow up with immutability: you don't change a string in place. Methods like trim() or replace() return a new string. That's why trying s[0] = 'H' does nothing useful.
In senior rounds you might hear UTF-16 — some characters (emoji) use two code units, so "👋".length === 2. Good to know; don't lead with it unless they go deep on Unicode.
Key takeaways
- •JavaScript strings are immutable UTF-16 sequences
- •Template literals support interpolation and multiline text
- •Common methods include slice, includes, split, and trim
- •Coercion with + often produces unexpected results in interviews
- •Unary + binds tighter than binary + — 'b' + 'a' + + 'a' + 'a' is "baNaNa"
Track your mastery
Sign in to save Q&A scores, coding challenge progress, points, and streaks across devices.
Sign in to save progress