Question about reversing string

Why does “return str” come before these other commands? Doesnt the function stop running after return is reached making it return the original str inputed? Also why are there no “;” in between the commands?

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

Thanks.

Andrej

Well, its spread across a bunch of lines. Here it is written a bit differently

function reverseString(str) {
  return str.split("").reverse().join("");
}
1 Like