Skip to main content

JavaScript

How JS works?

There are three components:

  1. Call stack
  2. Message queue
  3. Event loop

Event loop waits for a messages to arrive in the Message queue. The messages are processed in FIFO order, that's why it's called Message queue.

Prototypes

// Create an object
const MyObject = function () {};

// Add a property
MyObject.prototype.func1 = function () {};

// Use the property
const myObject = new MyObject();
myObject.func1();