js Intermediate

Reverse String in JavaScript

Reverse String in JavaScript
Reverse String Demo

Open this example in our interactive code editor to experiment with it.

Try the Editor

reverseString 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
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.