Hello, I have a question about this code snippet. Can you please explain why it is returning a function instead of the x value? Thank you in advance.
function f() {
function createClosure(x) {
return function(){
return x;
};
}
var arr = [];
var index;
for(index = 0; index < 3; index++) {
arr[index] = createClosure(index);
}
return arr;
}
var result = f();
console.log(result[0]);