Why we use var inside of the for loop for i, because it also without defining it


#1

var vacationSpots = [‘Ooty’,‘Singapore’,‘Malaysia’];
for(var i=0;i<vacationSpots.length;i++) {
console.log(vacationSpots[i]);
}
Vs****
var vacationSpots = [‘Ooty’,‘Singapore’,‘Malaysia’];
for(i=0;i<vacationSpots.length;i++) {
console.log(vacationSpots[i]);
}


#2

Try using

Found with google search
== Discussion / opinions ==
javascript why use var in for loop init site:stackoverflow.com


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.