> Articles > Factory Function In JavaScript

Factory Function In JavaScript

A factory function in JavaScript is used to create function objects.

What is Factory Function in JavaScript?

Factory function in JavaScript can have a function works as a factory which creates and returns function. We can return different functions based on parameter of function. As we have a function inside another function so closure is created and inner function will have access to factory function parameter even after it returns. This provides great flexibility for creation of functions. Let's see the implementation of factory function in JavaScript.

Implementation

factory-function.js

Factory Function in JavaScript - Example

Output

Factory Function in JavaScript - Example Output


Suresh Kumar Srivastava is founder of online learning site coursegalaxy.com and author of popular books C In Depth, Data Structures Through C In Depth. He has 18+ years experience in industry and worked on architecture and design of multiple products. This article Factory Function in JavaScript is from his Advanced JavaScript course.