Today, I learned one of the most important concepts in JavaScript: the Event Loop and the Concurrency Model.
JavaScript is Single-Threaded
JavaScript is a single-threaded language. This means it can execute only one piece of JavaScript code at a time.
For example:
console.log("A");
console.log("B");
console.log("C");
Output:
A
B
C
JavaScript executes these statements one after another.
What is the Call Stack?
The Call Stack is where JavaScript executes functions. Whenever a function is called, it is added to the stack. After the function finishes executing, it is removed from the stack.
Example:
function one() {
two();
}
function two() {
console.log("Hello");
}
one();
Execution order:
one()
↓
two()
↓
console.log()
↓
Stack becomes empty
The Call Stack follows the Last In, First Out (LIFO) principle.
What are Web APIs and Node APIs?
Some operations take time, such as:
Waiting for a timer
Making an API request
Reading a fi
Discussion
Say something first
It all starts with you—share your thoughts now.