Final answer:
The forEach loop applies a given function to each array element, for-of iterates over iterable objects, and for-in iterates over the keys of an object.
Step-by-step explanation:
The difference between the forEach, for-of, and for-in loops is as follows:
- forEach is a higher-order function that applies a given function once to each element in an array, but cannot be broken out of early using the break or continue statements.
- for-of loop is designed to iterate over iterable objects such as arrays, strings, maps, nodeLists, and more, providing a way to access the values directly with a simpler syntax compared to traditional for loops. The for-of loop also supports break, continue, and return within the block to control the flow.
- for-in loop is especially useful for iterating over the keys of an object, but it is not recommended for iterating over arrays as the order is not guaranteed and it may enumerate through non-element properties.
The correct option from the given choices would be C: 'ForEach is a higher-order function that applies a provided function once to each element in an array, for-of is used for iterating over iterable objects, and for-in is used to iterate over the keys of an object.'