✅Day-2 || 30-Days-JS-Challenge || Best Editorial || Everything Explained || Easy to understand ||🔥
Intuition\n1.The createCounter() function is designed to create a counter function that maintains and increments a specific value (n).\n2.By returning a nested 
# Intuition\n1.The $$createCounter()$$ function is designed to create a counter function that maintains and increments a specific value $$(n)$$.\n2.By returning a nested function, the $$createCounter()$$ function encapsulates the value $$n$$ within the returned counter function.\n3.Each time the counter function is invoked, it increments $$n$$ by 1 and returns the previous value of $$n$$.\n\n# Approach\n1.The createCounter function takes an initial value $$n$$ as a parameter.\n2.It returns a nested function that acts as the counter function.\n3.The counter function increments n using the post-increment operator $$++$$ and assigns the updated value to the variable $$ans$$.\n4.The counter function returns the previous value of $$n$$, which is stored in $$ans$$. \n\n# Complexity\n- Time complexity:\nThe time complexity of creating the counter function using $$createCounter()$$ is constant, $$O(1)$$, as it simply returns a nested function and does not involve any iterative or recursive operations.\nThe time complexity of invoking the counter function is also constant, $$O(1)$$, as it performs a single operation of incrementing $$n$$ and returning a value.(atmost $$1000$$ calls given in constraint)\n\n- Space complexity:\nThe space complexity of the createCounter function is constant, $$O(1)$$, as it does not create any data structures or variables that scale with the input size.\nThe space complexity of the counter function is also constant, $$O(1)$$, as it only uses a single variable $$(ans)$$ to store the updated value of $$n$$.\n\n# Code\n```\n/**\n * @param {number} n\n * @return {Function} counter\n */\nvar createCounter = function(n) {\n    return function() {\n        //creating answer variable\n        //postincrementing n after assigning to ans variable\n        var ans = (n++);\n        //return ans\n        return ans;\n    };\n};\n\n/** \n * const counter = createCounter(10)\n * counter() // 10\n * counter() // 11\n * counter() // 12\n */\n```\n$$Please \\space Upvote \\space My \\space Solution \\space if \\space You \\space Liked \\space it..$$\n![abc.png](https://assets.leetcode.com/users/images/8c23d533-3ba8-4e4f-b081-436f1bd0e5c5_1683395752.0296404.png)\n\n$$Thank \\space you \\space so \\space much$$\n
['JavaScript']