Threads in JavaScript (Part 1)

What are threads?

In an operating system, a process is a program that is loaded into memory. The process occupies real estate in memory until the process is terminated. A program is a set of instructions written for the computer. The number of lines or instructions that a program holds can vary from one line to a million. A process holds text, data, heap, and a stack. The Operating system maintains a process control block for each process, which holds information needed to execute the process. Every process goes through a life cycle. In each life cycle, there are five stages: new, ready, running, waiting, and terminated.

Whereas, a thread, also referred to as a lightweight process, exists within a process and avails the application’s performance by means of parallelism. A process can have multiple processes or just one single thread. Each of the threads shares information with each other including files, data, and code. When a process is multithreaded, parallel execution can occur. For instance, while one thread is blocked, another can continue the task. Giving the appearance that the program is running without interruption.

Interestingly, languages like Java, C, C++, Go, and Java support multithreading, but JavaScript does not. Why doesn’t Javascript support multithreading and how is it managing to provide a great user experience? Let’s first explore the environment JavaScript is used in the browser.

To be continued ...