How to reverse a string?

https://www.freecodecamp.org/challenges/reverse-a-string

Why doesn’t it work?


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

reverseString("hello");

You are creating a new string (by creating a new array, reversing it, and joining it) but you aren’t saving that new string. You aren’t assigning it to anything.

1 Like