Understanding javascript closures?

Example:


  function outer() {
      let num = 10;
      function inner() {
          console.log(num);
      }
      return inner;
  }
  let myFunc = outer();
  myFunc();  // Outputs: 10
  

Solution:

Closures in JavaScript are functions that have access to the parent scope, even after the parent function has closed. In the example, the `inner` function has access to the `num` variable from the `outer` function.

Beginner's Guide to JavaScript