JavaScript coding interview — Understand the looping/ iteration — Part 1

Photo by Sean Alabaster on Unsplash
for ([init]; [condition]; [increment])

“All the three blocks in the for loop can be omitted. But should be declared before.”

for (variable of iterable)

“Iterable can be ‘Array, String, array-like objects, TypedArray, Map, Set and user-defined iterables”.

typeof obj[Symbol.iterator] === 'function'; // 'obj' will be the var

Don’t use loop for arrays. It iterates over both array indices and property keys. It will be ambiguous if someone adds a property to an array.

function(callback, [thisValue])//callback will be
function callBackFn(value, index, array)
Exclusive awesome reference on forEach:
Great examples here:
arr.reduce(callback, initialValue);


important difference is that a loop enumerates properties in the prototype chain as well



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store