String Immutability
Multiple Choice Easy
Question
After let s = "cat"; s[0] = "b"; what is s?
Hint
Strings cannot be modified in place.
Explanation
Strings in JavaScript are immutable, meaning individual characters cannot be changed after creation. The assignment s[0] = "b" silently does nothing (in non-strict mode) or throws in strict mode. To change a string, you must create a new one, e.g. s = "b" + s.slice(1).
Related Resources
Related Lessons
- Strings and Text
Learn about strings.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.