🔢 Closure Counter: A JavaScript Function Factory! 🏭
Intuition: 🧠💡The core idea here is to create a function (createCounter) that acts as a factory. This factory produces a new function (a counter) each time it's
# Intuition: 🧠💡
The core idea here is to create a function (createCounter) that acts as a factory. This factory produces a new function (a counter) each time it's called. The created counter function, when repeatedly called, will return successive integers, starting from an initial value (n) that's passed to the factory. It's all about maintaining state between function calls using closures! 🔑

# Approach: 🎯
1. **createCounter Function:** This function takes an initial number n as input. Its job is to create and return another function.

2. **Inner (Counter) Function:** This inner function is the actual counter. Each time it's called, it does the following:
    - Returns the current value of n.
    - Increments n to prepare for the next call.

3. **Closure:** The secret ingredient! The inner function "closes over" the variable n from the outer function's scope. This means the inner function remembers n even after createCounter has finished executing. This allows the counter to maintain its state across multiple calls.

# Key Concepts: 🔑🧠
- **Function Factory:** createCounter creates and returns another function. 🏭
- **Closure:** The inner function retains access to the n variable from createCounter's scope, even after createCounter has finished. 🔒
- **Post-Increment Operator:** n++ returns the current value of n and then increments it. ➕

# Complexity Analysis: ⏱️ ⚙️
- Time Complexity: 
    - createCounter takes **O(1)** time (constant time) because it simply defines and returns a function. ⏱️
    - The counter function also takes **O(1)** time for each call (returning the current value and incrementing). ⏱️
- **Space Complexity:** 
    - O(1) - Because of the closure, the inner function 'remembers' the n variable (or its location in memory) even after createCounter has completed executing. 
    - The only space used will be the memory allocated to n, which will stay in memory due to the closure. 💾

# Code
```javascript []
/**
 * @param {number} n
 * @return {Function} counter
 */
var createCounter = function(n) {
    return function() {
        return n++;
    };
};

/** 
 * const counter = createCounter(10)
 * counter() // 10
 * counter() // 11
 * counter() // 12
 */
```
['JavaScript']