Strings are immutable

The immutable nature of strings is difficult to notice, since TypeScript will prevent most actions that attempt to directly mutate a string.

The program above is a valid JavaScript program, but it will not modify the original string:

Loading JavaScript...

The only way to capitalize a string is to create a duplicate version with modified characters.

Loading TypeScript...

Was this page helpful?