- 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
schoolkidSecondafter theschoolkidFirstvariable. Pass the string'dumplings'as an argument. - Then below it redefine the value of the global variable
foodto'celery'. - Then call the function from the
schoolkidFirstvariable. - Below that call the function from the
schoolkidSecondvariable. - Let’s now break our closure by removing the
foodparameter from thecollectContainerfunction. Let’s feed our students celery! Mu-ha-ha!
Comments