EASY 1 line Javascript Solution - Explained Solution
Intuition\nThe magic of retaining local variables in "memory" of Javascript Closure should come to mind when seeing such problem where we need to return a funct
# Intuition\nThe magic of retaining local variables in "memory" of Javascript Closure should come to mind when seeing such problem where we need to return a function inside another function and recall something from the memory.\n\n# Approach\nWe pass a value of `n` upon calling the `createCounter` method. The value of `n` is **remembered** by the following anonymous function because when the anonymous function is returned, it took the local variable `n` in its **backpack**/**closure**.\n\n*The closure is a collection of all the variables in scope at the time of creation of the function.*\n\n# Code\n```\n/**\n * @param {number} n\n * @return {Function} counter\n */\nvar createCounter = function(n) {\n    return function() {\n        return n++;\n    };\n};\n\n/** \n * const counter = createCounter(10)\n * counter() // 10\n * counter() // 11\n * counter() // 12\n */\n```
['JavaScript']