callback function syntax using forEach iterator method

PHOTO EMBED

Tue Aug 13 2024 20:05:41 GMT+0000 (Coordinated Universal Time)

Saved by @thecowsays #javascript

const fruits = ['mango', 'papaya', 'pineapple', 'apple'];

// Iterate over fruits below
fruits.forEach(item => console.log(`I want to eat a ${item}.`));
content_copyCOPY

forEach method takes a callback function for the argument, but will only ever return 'undefined' itself. Used here with an anonymous function via ES6 arrow function syntax.

www.codecademy.com