A factory function creates a new object and returns it. To create an object using an existing object as a prototype, use Object. construct().
Some benefits of using factory functions include:
Reduced duplication of code
Improved readability of the codebase
When you are working with a factory function, you are creating a function that runs on every item in the set that you pass in. This allows you to iterate over the items in your set and do something different for each one.
The factory function is a function that returns an object of the same type without using any of the properties or methods on that object. This can be helpful when you want to create a new instance of an object without using its constructor.