JavaScript String Methods

Every String prototype method with signature, return type and unicode notes

Searchable JavaScript String method reference. Each entry lists the call signature, return type, and unicode behaviour, with a reminder that strings are immutable so every method returns a new value rather than changing the original.

Are JavaScript strings mutable?

No. Strings are immutable primitives, so no method changes the string in place. Methods like toUpperCase, replace, and trim all return a brand-new string and leave the original unchanged. You must assign the result to keep it.

JavaScript strings are immutable, so every method here returns a new string or a derived value rather than changing the original. This reference lists each String.prototype method with its signature, return type, and the unicode gotchas that trip people up.

How it works

The methods group into a few jobs:

  • SearchindexOf, includes, startsWith, endsWith, match, search locate text.
  • Sliceslice, substring, substr, at extract portions.
  • TransformtoUpperCase, toLowerCase, trim, pad*, replace, replaceAll, repeat, normalize produce a new string.
  • Convertsplit, charAt, charCodeAt, codePointAt, localeCompare move between strings, arrays, and numbers.

Because strings are immutable, none of these mutate this; you always keep the return value.

Tips

Prefer slice over substring/substr for predictable negative-index behaviour. Use replaceAll for clear all-occurrence replacement and reserve replace for the first match or regex captures. When comparing user text, normalize('NFC') first so visually identical strings with different encodings compare equal. Remember length counts UTF-16 code units — to count visible characters iterate with for...of or [...str].length, which respect whole code points.