There are two initialisation and no "x<y" to limit the iterations. So how does this loop work?
var features = [{
position: new google.maps.LatLng(-33.91721, 151.22630),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91539, 151.22820),
type: 'info'
}, {
position: new google.maps.LatLng(-33.91747, 151.22912),
type: 'info'
}];
for (var i = 0, feature; feature = features[i]; i++) {
addMarker(feature);
}
featurewill always equalfeatures[i], andi++still increments. This should still loop over 3 times.forloop,for(initialization; condition; final-expression)i=3features[i] will returnundefinedand that will break the loopfeatures.forEach(addMarker), Of course you wanted to know why it worked, but for people browsing might be worth pointing out the forEach.forEachor any other method would be out of scope. But for anyone who is looking for it, please refer Different ways to loop through array