Skip to content

Instantly share code, notes, and snippets.

@marcoala
Last active January 24, 2017 14:21
Show Gist options
  • Save marcoala/e57f78de365f15826dcec786da87ee7d to your computer and use it in GitHub Desktop.
Save marcoala/e57f78de365f15826dcec786da87ee7d to your computer and use it in GitHub Desktop.
Ask the candidate what s/he can say about this code, and what the output is.
function createFunctions() {
var i;
var functions = [];
for (i = 0; i < 5; i++){
functions[i] = function(){
console.log(i);
};
}
return functions;
}
var funcs = createFunctions();
funcs[2]();
funcs[4]();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment