Interactive online courses HTML Academy
2026-03-09 10:55 Diff
  • script.js

JavaScript

var food = 'salad'; var collectContainer = function (food) { return function () { console.log('I ate ' + food); }; }; var schoolkidFirst = collectContainer('pasta');

Thanks! We’ll fix everything at once!

Result

  1. Create a similar variable schoolkidSecond after the schoolkidFirst variable. Pass the string 'dumplings' as an argument.
  2. Then below it redefine the value of the global variable food to 'celery'.
  3. Then call the function from the schoolkidFirst variable.
  4. Below that call the function from the schoolkidSecond variable.
  5. Let’s now break our closure by removing the food parameter from the collectContainer function. Let’s feed our students celery! Mu-ha-ha!