There’s something I’m not understanding…
In Java Script: Iterators 6/7:
let cities = ['Nashville', 'Charlotte', 'Asheville', 'Austin', 'Boulder']; // Choose a method that will return undefined cities.forEach(city => console.log('Have you visited ' + city + '?'));
I know the method .forEach is the correct answer, but why? How does it return undefined? I don’t seem to be able to observe it happening or understand why it would happen. if you call the ‘cities’ array after your answer it’s still the same array, nothing is undefined; the code in the lesson itself successfully prints to the console the text of each ‘city’ in the ‘cities’ array, nothing is undefined. How does the method return undefined?
I’ve read the MDN documentation and it, sure enough, says “undefined” under the “Return value” section. I find the description for why incredibly confusing-- If I spent a very long time I could probably figure it out, but considering I’ve been finding everything else quite easy to understand-- I’m thinking I must be missing something here. Is there a simple way to observe or understand how .forEach() is causing this code to return undefined?
A more clear question: if .forEach() is causing a return of undefined in the code above, what code could I add to make that return of undefined appear in the console?