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

Read complete blog post