Closures & Scope

Function Factories

Function Factories

A function factory creates functions that carry their own closed-over configuration. Each call to the factory creates a new environment, so each returned function can remember different data.

Factories become more useful when they combine saved configuration with private state. The returned function can use both the setup values and a changing counter that callers cannot edit directly.

Your task: Complete createTicketFormatter. It receives a prefix and returns a function. Each call to the returned function should receive a title and return a ticket label containing the prefix, the next number starting at 1, and the title.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Function Factories

A function factory creates functions that carry their own closed-over configuration. Each call to the factory creates a new environment, so each returned function can remember different data.

Factories become more useful when they combine saved configuration with private state. The returned function can use both the setup values and a changing counter that callers cannot edit directly.

Your task: Complete createTicketFormatter. It receives a prefix and returns a function. Each call to the returned function should receive a title and return a ticket label containing the prefix, the next number starting at 1, and the title.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Console

Run code to see output.