In JavaScript, a string is a sequence of characters—letters, numbers, symbols, even emojis—wrapped in quotes. You can use single quotes (‘Hello’), double quotes (“World”), or backticks (`Template`) to define them.

Strings are among the most used data types. They appear in many places, such as UI, URLs, and inputs.
However, a characteristic of strings often confuses newcomers. It is immutability.
When we say strings are immutable, we mean that you can’t change the contents of a string directly after it’s been created. Any operation that seems to modify a string actually creates and returns a new string.
Let’s look at this:

Strings don’t work like arrays. You can access characters using bracket notation, but you can’t assign to them a new value.
To “change” a string, you build a new one:

Why does immutability matter?
The fact that you can pass a string to a function and trust it won’t be altered, makes JavaScript predictable, better performing and safe.
Let’s see how:
Predictability: You Know What You’re Working With
Because strings are immutable, they will not change unexpectedly.

This predictability helps avoid bugs—especially in larger codebases or when working in teams.
Performance Optimizations
Because strings can’t change, JavaScript engines can safely cache and reuse them internally.
That means operations involving strings—like comparison, storage, or copying—can be faster. If a string can’t change, the engine doesn’t need to worry about tracking changes to it in memory.
For example, multiple variables can point to the same string without duplicating memory:

Safe to Share and Pass Around
With mutable values (like objects or arrays), passing them into functions or across components can lead to accidental side effects. However, strings don’t have that issue.

Encourages Clearer Code
Because each string transformation provides a new value, your code will naturally be cleaner.

Each step is explicit. That clarity proves particularly useful in complex applications.
Wrapping Up
Because they are immutable, strings are easier to use, safer to share, and less likely to cause errors in large apps.
This language design choice prevents many issues, particularly in complex code.