the part that i did not understand is how at the end of this code we get the output of
'olleh' basically the string reversed
yad I understand how the process happened but I don't understand why and how we return it at the end we are storing any thing for example we can just do let reversedString = //somthing
but when the base is completed we just return an empty String but we get the result we wanted
how is this happening !!
code:
function reverse(i) {
if (i.length === 0) {
return "";
}
return reverse(i.slice(1)) + i.charAt(0);
}
console.log(reverse("hello"));