What are the ways to reverse a string in JavaScript?
There are three common approaches and they differ in how they handle characters outside the basic multilingual plane.
The most direct one splits the string into an array, reverses it and joins it back. The array reverse method reverses in place and works on any array, so you need to turn the string into an array first. Splitting on an empty string splits it into code units, which is where the emoji problem comes from. Spreading the string instead gives you whole characters, so that is the version to prefer.
The second approach is a manual loop that builds the result one character at a time, either with the charAt method or by indexing. It is more code and slower, but it works and it is easy to read when you need to be explicit.
The third is the reverse method on the array prototype applied to a split result, which is the same as the first one but written differently.
One thing to know about the underlying methods. The array reverse method mutates the array it is called on, so if you reverse the result of a split you are fine, because the split produced a fresh array. The string reverse method does not exist, so any answer that claims otherwise is wrong.
For the interview, the version to reach for is the spread one, and the reason to give is that it handles astral characters correctly. If the input is guaranteed to be plain ASCII, the split-on-empty-string version is fine and marginally more familiar.