i was just watching Douglas Crockford videos and he gave the following exercise to do :
write a function, that when passed a variable, returns a function that if called , returns the value of the variable.
so i wrote the following function :
function funcky(o) {
return function send(o){ // notice the o in send
return o;
}
}
var x = funcky(3);
console.log(x()); // i get undefined why ??
notice the o
in send. i have been programming javascript for a while now , but i still don't understand why i get undefined ??
crockfords solution was as follows :
function funcky(o) {
return function send(){
return o;
}
}
var x = funcky(3);
console.log(x()); // get 3 now .
now how come this solution works and mine does't ? i don't see much of a difference in my solution and nothing is obviously wrong that i see. can anybody explain please ?