# JavaScript Reference: String

> A current reference to JavaScript strings, including Unicode behavior, static String methods, and common instance methods for searching and transforming text.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2019-03-13 | Updated: 2026-07-18 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/javascript-string/

JavaScript strings are immutable sequences of UTF-16 code units.

String indexes and `length` count UTF-16 code units, not necessarily user-perceived characters. The [MDN String reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) explains the Unicode details.

Call `String()` without `new` to convert a value to a string:

```js
String(42) //'42'
```

## Static methods

The `String` object has three static methods.

`String.fromCharCode()` creates a string from UTF-16 code units:

```js
String.fromCharCode(70, 108, 97, 118, 105, 111) //'Flavio'
```

`String.fromCodePoint()` creates a string from Unicode code points:

```js
String.fromCodePoint(70, 108, 97, 118, 105, 111) //'Flavio'
```

This matters for characters outside the basic multilingual plane:

```js
String.fromCodePoint(0x1F436) //'🐶'
```

`String.raw()` returns the raw text of a tagged template literal:

```js
String.raw`line 1\nline 2` //'line 1\\nline 2'
```

All other methods below are **instance methods**. JavaScript temporarily wraps a string primitive so you can call them directly.

## Instance methods

A string offers many methods. The most commonly used are:

- `at(i)`
- [`charAt(i)`](https://flaviocopes.com/javascript-string-charat/)
- [`charCodeAt(i)`](https://flaviocopes.com/javascript-string-charcodeat/)
- [`codePointAt(i)`](https://flaviocopes.com/javascript-string-codepointat/)
- [`concat(str)`](https://flaviocopes.com/javascript-string-concat/)
- [`endsWith(str)`](https://flaviocopes.com/javascript-string-endswith/)
- [`includes(str)`](https://flaviocopes.com/javascript-string-includes/)
- [`indexOf(str)`](https://flaviocopes.com/javascript-string-indexof/)
- [`lastIndexOf(str)`](https://flaviocopes.com/javascript-string-lastindexof/)
- [`localeCompare()`](https://flaviocopes.com/javascript-string-localecompare/)
- [`match(regex)`](https://flaviocopes.com/javascript-string-match/)
- `matchAll(regex)`
- [`normalize()`](https://flaviocopes.com/javascript-string-normalize/)
- [`padEnd()`](https://flaviocopes.com/javascript-string-padend/)
- [`padStart()`](https://flaviocopes.com/javascript-string-padstart/)
- [`repeat()`](https://flaviocopes.com/javascript-string-repeat/)
- [`replace(str1, str2)`](https://flaviocopes.com/javascript-string-replace/)
- `replaceAll(str1, str2)`
- [`search(regexp)`](https://flaviocopes.com/javascript-string-search/)
- [`slice(begin, end)`](https://flaviocopes.com/javascript-string-slice/)
- [`split(separator)`](https://flaviocopes.com/javascript-string-split/)
- [`startsWith(str)`](https://flaviocopes.com/javascript-string-startswith/)
- [`substring()`](https://flaviocopes.com/javascript-string-substring/)
- [`toLocaleLowerCase()`](https://flaviocopes.com/javascript-string-tolocalelowercase/)
- [`toLocaleUpperCase()`](https://flaviocopes.com/javascript-string-tolocaleuppercase/)
- [`toLowerCase()`](https://flaviocopes.com/javascript-string-tolowercase/)
- [`toString()`](https://flaviocopes.com/javascript-string-tostring/)
- [`toUpperCase()`](https://flaviocopes.com/javascript-string-touppercase/)
- [`trim()`](https://flaviocopes.com/javascript-string-trim/)
- [`trimEnd()`](https://flaviocopes.com/javascript-string-trimend/)
- [`trimStart()`](https://flaviocopes.com/javascript-string-trimstart/)
- [`valueOf()`](https://flaviocopes.com/javascript-string-valueof/)
- `isWellFormed()`
- `toWellFormed()`

Strings are immutable. These methods return new strings instead of changing the original value:

```js
const name = 'Flavio'
const upper = name.toUpperCase()

name //'Flavio'
upper //'FLAVIO'
```

Avoid the old HTML wrapper methods such as `bold()` and `fontcolor()`. They are deprecated. Use HTML and CSS instead.
