This part will be the shortest of all, but before the next posts, I would like to discuss these two concepts.
Although the explanations provided here will be useful in subsequent posts, I think that it is most appropriate to create a separate post to explain these concepts.
This means that in our code only one command at the time is being executed.
This is very similar to Single Threaded. In programming, it means one at a time. Not two or ten, just one at a time.
In addition, the code is not only executed one at the time but also in the order that it appears. Line by the line. That's it.
But hey hey, you might say. What about AJAX, doesn't A stand for Asynchronous ?
Let's take a look at this example.
As you see we have 2 functions. First one is simply to make sure it takes exactly 5 seconds to be finished. The Second one is to console.log when we click. Ignore document.addEventListener line since it will be discussed in the later part of the blog when we will talk about DOM Manipulation. The only thing you have to know now that it is needed for us to be able to console.log when we click using a mouse.
The task is to click during execution of the waitFiveSeconds function. If you do that the result will show.
We could have clicked as many times as we wanted during execution of waitFiveSeconds function but we wouldn't get anything until that function is executed. One command at the time.
I will talk about Invocation and Execution Stack.