As long as you're dealing with simple ASCII characters, and you're happy to use built-in functions, this will work:

function reverse(s){
    return s.split("").reverse().join("");
}

If you need a solution that supports UTF-16 or other multi-byte characters, be aware that this function will give invalid unicode strings, or valid strings that look funny. You might want to consider this answer instead.

The array expansion operator is Unicode aware:

function reverse(s){
    return [...s].reverse().join("");
}

Another Unicode aware solution using split(), as explained on MDN, is to use a regexp with the u (Unicode) flag set as a separator.

function reverse(s){
    return s.split(/(?:)/u).reverse().join("");
}
Answer from belacqua on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › reverse-a-string-in-javascript
Reverse a String in JavaScript - GeeksforGeeks
The spread operator(...) is used to spread the characters of the string str into individual elements. The reverse() method is then applied to reverse the order of the elements, and join() is used to combine the reversed elements back into a string.
Published   December 20, 2025
🌐
Programiz
programiz.com › javascript › examples › reverse-string
JavaScript Program to Reverse a String
In the above program, the user is prompted to enter a string. That string is passed to the reverseString() function.
Discussions

javascript - How do you reverse a string in-place? - Stack Overflow
Because it contains an astral symbol ... pairs in JavaScript) and a combining mark (the ñ in the last mañana actually consists of two symbols: U+006E LATIN SMALL LETTER N and U+0303 COMBINING TILDE). The order in which surrogate pairs appear cannot be reversed, else the astral symbol won’t show up anymore in the ‘reversed’ string. That’s why you saw those �� marks in the output for the previous example... More on stackoverflow.com
🌐 stackoverflow.com
Reversing a string - Blog Post
What’s the use-case? More on reddit.com
🌐 r/learnjavascript
14
3
July 22, 2023
How to split a string on a backslash (\)?
Backslash is an escape character. It lets you insert newline and other characters into strings. Eg. "Hello\nWorld" would be printed on two lines. To do what you want, you need to escape the escape character. Eg. "hello\world".split("\") The first backslash in each pair is saying "treat this next backslash as a printed character and not an escape character." More on reddit.com
🌐 r/javascript
9
0
November 1, 2011
Can someone please explain how/why this works? (recursive reverse string function)
The previous str[0]s are 'stored' in the stack of the previous calls to the function 'reverse'. That's not entirely accurate, but it's the closest answer I have to the question. The best way to look at this, and other recursive functions, is with a sample run: reverse("hello") --> str.length>1? yes ==> return reverse("ello")+'h' reverse("ello") --> str.length>1? yes ==> return reverse("llo")+'e'. ...same thing for 'll'... reverse('o') --> str.length>1? no ==> return 'o'. Now here's where it gets interesting. The last function call returns 'o'. The one-before-last function call receives that 'o' (from 'return reverse('o');'), adds its str[0] to the result (resulting in 'ol'), and returns that. The function call before that receives the 'ol' and does the same, and so forth, until we end up at the last (i.e. the first) return statement: return reverse('ello')+'h' which, by now, has finished evaluating 'reverse('ello')' and found it to be 'olle', and all it has to do is add the 'h' and return 'olleh'. More on reddit.com
🌐 r/learnjavascript
5
3
April 22, 2015
🌐
freeCodeCamp
freecodecamp.org › news › how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb
Three Ways to Reverse a String in JavaScript
March 14, 2016 - The split() method splits a String object into an array of string by separating the string into sub strings. The reverse() method reverses an array in place.
🌐
ReqBin
reqbin.com › code › javascript › lqai57s8 › javascript-reverse-string-example
How do I reverse a string in JavaScript?
You can also reverse a string with ... string. In this JavaScript Reverse String example, we reverse a string using the split(), reverse(), and join() methods....
🌐
SamanthaMing
samanthaming.com › pictorials › how-to-reverse-a-string
How to Reverse a String in JavaScript | SamanthaMing.com
Write a function that reverse a string. ... In JavaScript, there is no built-in method to reverse a string. There is however, a built-in method to reverse an array.
Top answer
1 of 16
1019

As long as you're dealing with simple ASCII characters, and you're happy to use built-in functions, this will work:

function reverse(s){
    return s.split("").reverse().join("");
}

If you need a solution that supports UTF-16 or other multi-byte characters, be aware that this function will give invalid unicode strings, or valid strings that look funny. You might want to consider this answer instead.

The array expansion operator is Unicode aware:

function reverse(s){
    return [...s].reverse().join("");
}

Another Unicode aware solution using split(), as explained on MDN, is to use a regexp with the u (Unicode) flag set as a separator.

function reverse(s){
    return s.split(/(?:)/u).reverse().join("");
}
2 of 16
440

The following technique (or similar) is commonly used to reverse a string in JavaScript:

// Don’t use this!
var naiveReverse = function(string) {
    return string.split('').reverse().join('');
}

In fact, all the answers posted so far are a variation of this pattern. However, there are some problems with this solution. For example:

naiveReverse('foo 𝌆 bar');
// → 'rab �� oof'
// Where did the `𝌆` symbol go? Whoops!

If you’re wondering why this happens, read up on JavaScript’s internal character encoding. (TL;DR: 𝌆 is an astral symbol, and JavaScript exposes it as two separate code units.)

But there’s more:

// To see which symbols are being used here, check:
// http://mothereff.in/js-escapes#1ma%C3%B1ana%20man%CC%83ana
naiveReverse('mañana mañana');
// → 'anãnam anañam'
// Wait, so now the tilde is applied to the `a` instead of the `n`? WAT.

A good string to test string reverse implementations is the following:

'foo 𝌆 bar mañana mañana'

Why? Because it contains an astral symbol (𝌆) (which are represented by surrogate pairs in JavaScript) and a combining mark (the in the last mañana actually consists of two symbols: U+006E LATIN SMALL LETTER N and U+0303 COMBINING TILDE).

The order in which surrogate pairs appear cannot be reversed, else the astral symbol won’t show up anymore in the ‘reversed’ string. That’s why you saw those �� marks in the output for the previous example.

Combining marks always get applied to the previous symbol, so you have to treat both the main symbol (U+006E LATIN SMALL LETTER N) as the combining mark (U+0303 COMBINING TILDE) as a whole. Reversing their order will cause the combining mark to be paired with another symbol in the string. That’s why the example output had instead of ñ.

Hopefully, this explains why all the answers posted so far are wrong.


To answer your initial question — how to [properly] reverse a string in JavaScript —, I’ve written a small JavaScript library that is capable of Unicode-aware string reversal. It doesn’t have any of the issues I just mentioned. The library is called Esrever; its code is on GitHub, and it works in pretty much any JavaScript environment. It comes with a shell utility/binary, so you can easily reverse strings from your terminal if you want.

var input = 'foo 𝌆 bar mañana mañana';
esrever.reverse(input);
// → 'anañam anañam rab 𝌆 oof'

As for the “in-place” part, see the other answers.

🌐
DEV Community
dev.to › swarnaliroy94 › reverse-a-string-in-javascript-e1i
Reverse a String in JavaScript - DEV Community
September 10, 2021 - If we compare it with the basic syntax of reduce(), reversed is the previous value/accumulator and character is the current value. The function stringReversed returns the current value adding it with the previous value, which is actually reversing the whole array characters and joining them together in a reversed way. This code block can be more compact if we use JavaScript ES6 syntax.
Find elsewhere
🌐
DEV Community
dev.to › tpointtech123 › how-to-reverse-a-string-in-javascript-using-a-for-loop-1aof
How to Reverse a String in JavaScript Using a For Loop - DEV Community
March 20, 2025 - Step 5: Once the loop completes, the function returns the fully reversed string. For example, if the input is "hello", the for loop will start with o (index 4), then move to l (index 3), and so on until it reaches h (index 0).
🌐
Stack Abuse
stackabuse.com › how-to-reverse-a-string-in-javascript
How to Reverse a String in JavaScript
September 28, 2023 - The simplest way to reverse a string in JavaScript is to split a string into an array, reverse() it and join() it back into a string.
🌐
Medium
medium.com › @umar.bwn › how-to-reverse-a-string-in-javascript-exploring-the-best-techniques-bac5d5c3ac6
How to Reverse a String in JavaScript: Exploring the Best Techniques | by Umar Farooq | Medium
June 23, 2023 - In this example, we define a function called reverseString() that takes a string as an argument. Within the function, we initialize an empty string called reversedStr. Using a for loop, we iterate over each character of the input string in reverse ...
🌐
Vultr Docs
docs.vultr.com › javascript › examples › reverse-a-string
JavaScript Program to Reverse a String | Vultr Docs
November 19, 2024 - This code uses recursion to build the reverse string by decomposing the input string until it’s empty. Each recursive call handles one character less than the previous call and adds the last character of the current string to the result.
🌐
Edd Mann
eddmann.com › posts › ten-ways-to-reverse-a-string-in-javascript
Ten ways to reverse a string in JavaScript - Edd Mann
October 31, 2011 - I successfully created a function that did as requested (using a decrementing for-loop and concatenation), though I realised that using concatenation would result in a new string being created in memory upon each iteration, as strings are immutable objects. I solved this by using a StringBuilder to append each character and then returning the result. On the way home, I began to think of the endless ways in which you could reverse a string in code (extremely sad, I know).
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-basic-exercise-48.php
JavaScript basic: Reverse a given string - w3resource
This JavaScript program reverses a given string. It iterates through the characters of the string from the last to the first and constructs a new string by appending each character in reverse order.
🌐
Inspector
inspector.dev › home › how to reverse a string in javascript – fast tips
How to reverse a string in Javascript - Fast tips - Inspector.dev
November 7, 2024 - It alters the original string, which can be troublesome if other sections of your code rely on the original string. let original = "Hello World"; let reversed = ""; for (let i = original.length - 1; i >= 0; i--) { reversed += original[i]; } ...
🌐
DEV Community
dev.to › onlinemsr › javascript-reverse-string-3-best-ways-to-do-it-8co
JavaScript Reverse String: 3 Best Ways To Do It - DEV Community
July 3, 2023 - The reduce() function is a more elegant way of reversing a string in JavaScript. This method takes each array element and applies a function to it, reducing the array to a single value. When using this method to reverse a string, use the reduce() function to loop through the characters and concatenate them to a new string in reverse order. Here’s an example reverse a string using the split() and reduce() methods:
🌐
Flexiple
flexiple.com › javascript › reverse-string-javascript
Methods to reverse string in JavaScript - Flexiple
March 15, 2022 - In this short tutorial, we have looked at three different methods of reversing a string in JavaScript.
🌐
CoreUI
coreui.io › answers › how-to-reverse-a-string-in-javascript
How to reverse a string in JavaScript · CoreUI
May 18, 2026 - Be aware that this method doesn’t handle Unicode surrogate pairs correctly; for international text, use Array.from(text).reverse().join('') or [...text].reverse().join('') to properly handle complex characters. To learn more about the split() step in this chain, see how to convert a string to an array in JavaScript.
🌐
Medium
medium.com › sonyamoisset › reverse-a-string-in-javascript-a18027b8e91c
Reverse a String in JavaScript. This article is based on Free Code Camp… | by Sonya Moisset | iDevOI | Medium
November 25, 2016 - For this solution, you will use three methods: the String.prototype.split() method, the Array.prototype.reverse() method and the Array.prototype.join() method. The split() method splits a String object into an array of string by separating the ...
🌐
Rip Tutorial
riptutorial.com › reverse string
JavaScript Tutorial => Reverse String
function reverse(string) { var strRev = ""; for (var i = string.length - 1; i >= 0; i--) { strRev += string[i]; } return strRev; } reverse("zebra"); // "arbez"