I am currently using a for loop in javascript to iterate over an array. Its working fine, but I can still get the variable value used in for loop outside the loop. I am not able to find the cause. Here is the code snippet.
var list = ['delhi','mumbai','pune','kolkata'];
for (let i = 0, max = list.length ; i < max ; i++ ){
var current_city = list[i];
//other code goes here
}
console.log(current_city);
It's printing 'kolkata' outside the for loop.