js Intermediate
Reverse String in JavaScript
Open this example in our interactive code editor to experiment with it.
Try the EditorreverseString one-liner
const reverseString = (string) => [...string].reverse().join("");
Summary
- The spread operator
[...string]splits the string into an array of individual characters. This is preferred over.split("")because it correctly handles Unicode characters like emojis. - The
.reverse()method reverses the array of characters in place. - The
.join("")method joins the reversed array back into a single string with no separator. - Chaining these three operations together creates a clean one-liner for reversing any string in JavaScript.
Try this in our interactive code editor
Practice hands-on with our built-in code sandbox.
Open Code Editor
Adrian Bigaj
Creator of BigDevSoon
Full-stack developer and educator passionate about helping developers build real-world skills through hands-on projects. Creator of BigDevSoon, a vibe coding platform with 21 projects, 100 coding challenges, 40+ practice problems, and Merlin AI.
Related Pills
js Intermediate
JavaScript multiple condition checks
Checking multiple values in JavaScript often leads to redundant, boilerplate code - let's use .includes method to fix that.
js Intermediate
Convert JavaScript data structures
Converting data structures is a day-to-day job as a Developer.
js Intermediate
ECMAScript new features
Null coalescing operator, optional chaining, and Array.flat method are all amazing.