The Singleton pattern is to ensure there is only one instance of the class that exists. In the case it does exist it returns a reference to that object. This is normally achieved by a method belonging to the class to create an instance.
Singleton in JavaScript is useful to for providing a single point of access to functions which are isolated from the global namespace.
Example are written in ES2015 syntax.
Basic and typical implementation of a Singleton in JavaScript using an object literal:
Maybe you want to have private fields and functions? These can be encapsulated inside of a closure and return a object literal to expose the public interface.
Another technique is to instantiate the class when it’s needed which can help save on resource: