As JS is single-threaded, only one operation can occure at the time. To be able to perform multiple operations at the same time but to also keep a track of their order of execution, we have to use different techniques to make sure these operations don't block the main thread and program execution. These are callbacks, event, promises and async/await. They allow us to run code asynchronously without blocking the program execution.
Let's write a function whose execution time will depend on some external influence - in this case the setTimeout()
method:
function printString(str) {
setTimeout(() => {
console.log(str);