Hello campers,
I would appreciate if anyone can explain to me why this code’s output is undefined
:
function checker(value) {
if (Array.isArray(value)) {
value.forEach(insideVal => {
return checker(insideVal);
});
}
else return value;
}
console.log(checker([1,2,3])); // -> undefined
while this one is OK:
function checker(value) {
if (Array.isArray(value)) {
value.forEach(insideVal => checker(insideVal));
}
else return value;
}
console.log(checker(1)); // -> 1
In the first case I expected to see something like
1
2
3
Any help will be appreciateed!