Implement a function makeCounter
that accepts an optional integer value and returns a function. When the returned function is called initially, it returns the initial value if provided, otherwise 0. The returned function can be called repeatedly to return 1 more than the return value of the previous invocation.
const counter = makeCounter();counter(); // 0counter(); // 1counter(); // 2
With a custom initial value:
const counter = makeCounter(5);counter(); // 5counter(); // 6counter(); // 7
Implement a function makeCounter
that accepts an optional integer value and returns a function. When the returned function is called initially, it returns the initial value if provided, otherwise 0. The returned function can be called repeatedly to return 1 more than the return value of the previous invocation.
const counter = makeCounter();counter(); // 0counter(); // 1counter(); // 2
With a custom initial value:
const counter = makeCounter(5);counter(); // 5counter(); // 6counter(); // 7
console.log()
语句将显示在此处。