To reverse a string in JavaScript, split it into characters, reverse the array and join it back: str.split("").reverse().join(""). That works for plain ASCII text, but it breaks on emoji and combined characters, so for real user text you should split with the spread operator or Intl.Segmenter instead. This guide shows the classic method, why it fails on some input, and safer alternatives.
Strings are immutable in JavaScript, so there is no in-place reverse. Every approach builds a new string. Interviewers ask this question to see whether you know that, and whether you know that reverse() exists only on arrays.
Strings have no reverse() method, but arrays do. So you convert the string to an array, reverse it, and convert it back.
Step by step:
split("") turns "hello" into ["h", "e", "l", "l", "o"].reverse() reverses that array in place and returns it.join("") glues the elements into one string with no separator.The original word is unchanged, because reverse() worked on the temporary array, not on the string.
split("") cuts the string into UTF-16 code units, not into characters you see. Characters outside the Basic Multilingual Plane, such as most emoji, use two code units (a surrogate pair). Reversing the units separates the pair and produces garbage.
The length is 4, not 3, and the emoji turns into two broken halves. The same problem affects letters built from a base character plus a combining accent, and emoji sequences such as family or flag emoji.
Strings are iterable by code point, so the spread operator keeps surrogate pairs together.
Array.from(text) does the same thing. This is the best short answer for most code. It still splits combined sequences, for example a family emoji built from several code points joined by zero-width joiners.
A grapheme is one user-perceived character. Intl.Segmenter is available in all current browsers and in Node.js, and it splits text the way a reader sees it.
Here the accented é (written as e plus a combining accent) and the family emoji both stay intact. Use this version when the input comes from users.
Writing the logic by hand is a common interview variation. A loop that walks the string from the end works, and so does reduce.
Using for...of iterates by code point, so both handle emoji. Avoid a classic for (let i = str.length - 1; i >= 0; i--) loop with str[i] if emoji matter, because it indexes code units.
| Method | Handles emoji | Handles combined characters | Notes |
|---|---|---|---|
split("").reverse().join("") | No | No | Fine for ASCII only |
[...str].reverse().join("") | Yes | No | Best short answer |
Intl.Segmenter graphemes | Yes | Yes | Best for user text |
for...of loop | Yes | No | Shows the logic without arrays |
Reversing a string with repeated concatenation is fine for short text. Modern engines optimise string building well, so you do not need to push into an array first unless you are measuring a real problem.
No. reverse() exists on arrays only, so you convert the string to an array first and join it afterwards.
No. Strings are immutable, and reverse() runs on a temporary array. The original string stays as it was.
You split the string into UTF-16 code units and separated a surrogate pair. Use the spread operator or Intl.Segmenter instead of split("").
Not for strings. You can only create a new string. Array.prototype.toReversed() also returns a copy of an array, but you still need join("") afterwards.
Use [...str].reverse().join("") as your default way to reverse a string in JavaScript, and Intl.Segmenter when the text may contain combining accents or emoji sequences. The older split("") version is correct only for simple ASCII. Remember that strings are immutable, so every method returns a new string.