I am currently studying Chapter 3 on Functions from a book called "Eloquent JavaScript".
Although I understand most of the code presented, one thing puzzles me.
Why do the sub-functions within the code snippet not have return statements?
var landscape = function() {
var result = "";
var flat = function(size) {
for (var count = 0; count < size; count++)
result += "_";
};
var mountain = function(size) {
result += "/";
for (var count = 0; count < size; count++)
result += "'";
result += "\\";
};
flat(3);
mountain(4);
flat(6);
mountain(1);
flat(1);
return result;
};
console.log(landscape());
// → ___/''''\______/'\_
Perhaps I am overlooking something crucial about the role of return statements despite consulting various sources for clarification.
I've experimented with adding return statements to the sub-functions. However, it either prematurely ends the function or yields identical results as if no return statement was included.
Thank you for taking the time to read this inquiry.