Reverse string - could someone explain how to do it and why?


When is reversing a string useful? I found a few ways to do that, here is one way but I just don't understand the code:

function reverseString(str) {
    return str.split('').reverse().join('');



Just off, I can't come up with any really good reasons to reverse a string, but sure enough it will come up at some point as just the right solution for a problem. Take for example a palindrome search program.

function isPalindrome(str) {
    if (str === reverseString(str)) {
        console.log(str + " is a palindrome.");