I was going through JS practise code (for interview) and I saw that the instructor have used/assigned empty array in function parameter
function walk(collection, result = []) {
collection.forEach(item => {
if(isTheItem(item)) result.push(item);
else walk(item[0].children, result);
});
return result;
}
In general, is the above code and the following code equal
function walk(collection) {
const result = []
collection.forEach(item => {
if(isTheItem(item)) result.push(item);
else walk(item[0].children, result);
});
return result;
}
Even from the recursive point of view? and if not, can someone please explain me the difference?