JavaScript Module design pattern

JavaScript modules are the most used design pattern to keep your code separate from your components which provides loose coupling to your code. Modules are JavaScript classes, which provides protection of states and behaviours from being accessed by other classes. The module pattern allows for public and private access levels. This is how the code looks like: (function() { // declare private variables and/or functions return { // declare public variables and/or functions } })(); Here we have to instantiate the private variables and functions before returning our object. Code outside of our function is unable to access these private variables since it is