Reversing a string means producing a new string with the characters in the opposite order — "hello" becomes "olleh". JavaScript strings don't have a built-in .reverse() method (that method belongs to arrays), so reversing one usually means converting it to an array first, or looping through it manually.
Reverse a String Using split(), reverse(), and join()
This is the shortest and most common way to reverse a string in JavaScript, chaining three built-in methods together.
function reverseString(str) {
return str
.split("") // "hello" -> ["h","e","l","l","o"]
.reverse() // -> ["o","l","l","e","h"]
.join(""); // -> "olleh"
}
console.log(reverseString("hello"));
Output:
olleh
split("") breaks the string into an array of single characters, the array's built-in .reverse() flips their order in place, and join("") glues them back into a string with nothing in between. It's concise, but be aware it can mishandle some multi-byte emoji and combining characters — fine for most everyday text, worth knowing about for text processing at scale.
Reverse a String Using a Manual Loop
It helps to also know how to do this without relying on built-in shortcuts, using a loop that walks the string backwards and builds up the result character by character.
function reverseStringManual(str) {
let reversed = "";
for (let i = str.length - 1; i >= 0; i--) {
reversed += str[i];
}
return reversed;
}
console.log(reverseStringManual("JavaScript"));
Output:
tpircSavaJ
The loop starts at the last index (str.length - 1) and counts down to 0, appending each character to reversed as it goes — so the string is naturally built in reverse order.
