- script.js
JavaScript
var food = 'salad';
var collectContainer = function (food) {
return function () {
console.log('I ate ' + food);
};
};
var schoolkidFirst = collectContainer('pasta');
Result
Goalscompleted
- Create a similar variable
schoolkidSecond
after theschoolkidFirst
variable. Pass the string'dumplings'
as an argument. - Then below it redefine the value of the global variable
food
to'celery'
. - Then call the function from the
schoolkidFirst
variable. - Below that call the function from the
schoolkidSecond
variable. - Let’s now break our closure by removing the
food
parameter from thecollectContainer
function. Let’s feed our students celery! Mu-ha-ha!
Comments