Observer & Singleton Patterns

How can the Singleton Pattern be implemented to be thread-safe in JavaScript?
let instance = null;

class ThreadSafeSingleton {
  constructor() {
    if (instance) {
      return instance;
    }
    this.initialize();
    instance = this;
    Object.freeze(instance);
  }

  static getInstance() {
    if (!instance) {
      instance = new ThreadSafeSingleton();
    }
    return instance;
  }

  initialize() {
    // Initialize singleton state
  }
}
Next Question (9/15)