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
reverse(): This method reverses the order of elements in the array, swapping the first element with the last, and so on. join(): This method combines all elements of the array back into a single string, using an optional separator.
Published   December 20, 2025
🌐
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 - Interviewers may ask you to write different ways to reverse a string, or they may ask you to reverse a string without using in-built methods, or they may even ask you to reverse a string using recursion. There are potentially tens of different ways to do it, excluding the built-in reverse function, as JavaScript does not have one.
Top answer
1 of 16
1016

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.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › reverse
Array.prototype.reverse() - JavaScript | MDN
In other words, elements order in the array will be turned towards the direction opposite to that previously stated. To reverse the elements in an array without mutating the original array, use toReversed().
🌐
Inspector
inspector.dev › home › how to reverse a string in javascript – fast tips
How to reverse a string in Javascript - Fast tips
November 7, 2024 - Three basic ways to reverse a string in JavaScript: utilizing the built-in reverse() method, a for loop, and the spread operator + reverse().
🌐
OutSystems
outsystems.com › forums › discussion › 101870 › how-to-reverse-string-using-javascript
How to reverse string using Javascript | OutSystems
March 6, 2025 - How to reverse string using Javascript also how to assign it in output · Everyone here is giving the exact same answer. Turns string into array and reverse the array
🌐
Programiz
programiz.com › javascript › examples › reverse-string
JavaScript Program to Reverse a String
Reverse the given string str and return it. For example, if str = "Hello World!", the expected output is "!dlroW olleH". ... Your builder path starts here. Builders don't just know how to code, they create solutions that matter. Escape tutorial hell and ship real projects.
🌐
LeetCode
leetcode.com › problems › reverse-string
Reverse String - LeetCode
The input string is given as an array of characters s. You must do this by modifying the input array in-place [https://en.wikipedia.org/wiki/In-place_algorithm] with O(1) extra memory.
Find elsewhere
🌐
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.
🌐
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 - Reversing a String in JavaScript using a for loop is a simple yet powerful technique. By starting from the last character of the string and working backward, you can append each character to a new string, effectively reversing it.
🌐
Vultr Docs
docs.vultr.com › javascript › examples › reverse-a-string
JavaScript Program to Reverse a String | Vultr Docs
November 19, 2024 - Convert the string into an array using the split('') method. Reverse the array using the reverse() method.
🌐
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 - The Array.from() method can be utilized to reverse a string in JavaScript. This method creates a new array instance from an iterable object, such as a string. By passing the string as the iterable object and then using the reverse() method, ...
🌐
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).
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › reverse-a-string
Reverse a String – Complete Tutorial - GeeksforGeeks
The idea is to start at the last character of the string and move backward, appending each character to a new string res. This new string res will contain the characters of the original string in reverse order.
Published   5 days ago
🌐
RunJS
runjs.app › blog › reverse-a-string-in-javascript
Reverse a String in JavaScript: 3 Expert Methods You Should Know
June 15, 2023 - There can be limitations and potential issues like character encoding, multibyte, Unicode characters, and performance. For example, using split, reverse, and join creates an array from the string, reverses the array, and then joins it back into a string, which can be inefficient for large strings. What is the fastest way to reverse a string JavaScript?
🌐
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 - To reverse a string, you can use one of the JavaScript Array Methods reverse() to reverse a string. Reverse a String In JavaScript using Reverse() Method
🌐
W3Schools
w3schools.com › js › js_string_methods.asp
JavaScript String Methods
1 week ago - The method takes 2 parameters: start position, and end position (end not included). Slice out a portion of a string from position 7 to position 13: let text = "Apple, Banana, Kiwi"; let part = text.slice(7, 13); Try it Yourself » · JavaScript counts positions from zero.
🌐
Medium
medium.com › codex › reverse-string-on-javascript-d6a4e0ce8c68
Reverse String on JavaScript. Did you ever try to read an open book… | by Norberto Santiago | CodeX | Medium
December 24, 2021 - As you can see in the for loop, the i starting point represents the last character of the string. As long as i is longer or equals 0, i will decrement. For each iteration, the last character will be added to newString, forming the result reversed string we want. ... We get a pool. ... Now that we tried reversing with the good old for loop, let’s go ahead and do some JavaScript ...
🌐
ReqBin
reqbin.com › code › javascript › lqai57s8 › javascript-reverse-string-example
How do I reverse a string in JavaScript?
December 16, 2022 - To reverse a string in JavaScript, you can use a combination of three built-in methods: split(), reverse(), and join(). The first method splits a string into an array of characters and returns a new array.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String
String - JavaScript | MDN
It is in the range 0xDC00–0xDFFF, inclusive (i.e., is a trailing surrogate), but it is the first code unit in the string, or the previous code unit is not a leading surrogate. Lone surrogates do not represent any Unicode character. Although most JavaScript built-in methods handle them correctly because they all work based on UTF-16 code units, lone surrogates are often not valid values when interacting with other systems — for example, encodeURI() will throw a URIError for lone surrogates, because URI encoding uses UTF-8 encoding, which does not have any encoding for lone surrogates.