JavaScript started as a single-threaded synchronous language. A programming language that is supposed to run on a single thread means that this can be able to do only one thing at a time. Doing one thing at a time will require it to follow some execution order. It is thus called synchronous.
In the case of synchronous JavaScript, code will be executed line by line. Here’s an example:
let a = 5;
let b = 10;
let c = b/a;
print(c)
Each line is executed one by one. Synchronous code is also called blocking. This is because line 2 can’t be executed until line 1 is done executing. You might not realise the “blocking” in this example because operations are usually quick.
Concurrency Model in JavaScript
Single-Threaded: JavaScript is a single-threaded language. This means all applications ever written using JavaScript will use only one thread to run. This idea of a single thread is unpopular among the likes of languages like Java and Python, which use Multithreading. (Doing multiple things with more than one thread at once). Single-threaded also means that the order of execution is always one at a time.
Non-Blocking: To put it simply, non-blocking means that the execution of the program will not be blocked because of some independent code that takes an unusually long time to execute. If line one has a slow operation, it should not block line two, which is independent of line 1, from executing.
Note: The concept of non-blocking applies only when two operations are independent of each other. Any succeeding operation that has a dependency on the result of the previous operation should always wait.
Concurrent: When multiple operations happen simultaneously, they are called concurrent.
Asynchronous: Asynchronous means that the code can execute immediately. This is unlike the synchronous code, which blocks the execution of the next lines of code until the current line is executed. We will dive deeper into the lines to come.
resource: https://www.scaler.com/topics/javascript/event-loop-in-javascript/
ast : https://astexplorer.net/
one thread == one call stack == one thing at a time
setTimeOut is not guaranteed to execute, it's a minimum time to execution, just like setting setTimeOut is set to "zero" doesn't run immediately, it runs the code next at some time.