Search code examples
javascriptfunctionmoduleconstructorfactory

What is the difference between module and factory function?


I am struggling with the concept of modules, factory functions, and constructors...

I am the most curious about the difference between module and factory function, and when to use what?


Solution

  • The main difference between modules and factory functions are simpler than you think.

    Modules are just files with blocks of code that you can import/export.

    Whereas factory functions are functions that create objects and return them. Also you might find this other stack overflow post that explains constructor functions vs factory functions:

    Constructor function vs Factory functions