so here is an example from the website(see below text) of a reversed string function executed with recursion and I’m curious to understand: 1) why if I switch the return line inner actions like this:
’ return word.charAt(0) + reversed(word.substring(1))’
I get the string again not reversesd.
2) where the ‘word.charAt()’ letters are being saved, memory wise what I miss here, what keeps them accumulated with tact and where are they ‘going’
overall I’d like a good article or explanation of some kind to how the memory concept works in js(or coding overall) to understand better the relations as I code.
I hope I’m clear and I’m here to learn:)
function reverseString(str) {
if (str === "")
return "";
else
return reverseString(str.substr(1)) + str.charAt(0);
}
reverseString("hello");
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.