---
title: "Discussion on \"Singleton Pattern in Javascript\" | Hashnode"
description: "Discussion on \"Singleton Pattern in Javascript\". Design Pattern"
url: "https://hashnode.com/posts/singleton-pattern-in-javascript/608d4c86a3716542f363f123"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Singleton Pattern in Javascript](https://bibekkakati.hashnode.dev/singleton-pattern-in-javascript?utm_source=hashnode&utm_medium=feed)

Design Pattern

May 1, 2021 · 3 min read · bibekkakati.hashnode.dev  
Updated May 12, 2021  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#design-patterns](https://hashnode.com/tag/design-patterns)
-   [#nodejs](https://hashnode.com/tag/nodejs)
-   [#2articles1week](https://hashnode.com/tag/2articles1week)
-   [#web-development](https://hashnode.com/tag/web-development)

## Written by

[Bibek Kakati](https://hashnode.com/@bibekkakati)

@bibekkakati · India

  
[View profile](https://hashnode.com/@bibekkakati)

Software Engineer • Backend & AI Engineering

Software Engineer with 5+ years of experience building scalable backend and distributed systems across domains and AI.

## Responses 1

Markdown supported · ⌘↵ to post

[Tony B](https://hashnode.com/@octree)

[May 1, 2021](https://hashnode.com/posts/singleton-pattern-in-javascript/608d4c86a3716542f363f123/comment/608d8459a3716542f363f46c)

Although there are a lot of good uses for Singletons, this example is a little ironic. The use of a Module means there is only one instance of the Singleton constant, so the entire class is unnecessary. In rare cases where complex dependencies and versions create multiple instances of a module, your example wouldn't work anyway as there would be multiple instances.

i.e. just use **const Singleton = new Username()** in your module and move on :)

[Bibek Kakati](https://hashnode.com/@bibekkakati)

[May 1, 2021](https://hashnode.com/posts/singleton-pattern-in-javascript/608d4c86a3716542f363f123/comment/608d8459a3716542f363f46c#reply-608d8bd5a3716542f363f4c4)

Hey Tony, you are right we can use the Singleton constant directly and this is just a basic example to show the use case. And I always prefer to follow the common implementation way of these design patterns. We can use the same pattern inside class-based Singleton too. At last, we have two choices in javascript, either modularisation approach or singleton approach.
