Really trying to understand the event queue of javascript. My current understanding is the following.
Code:
let doSomething = (callback) => {
callback("first");
};
let foo = (text) => {
console.log(text);
};
doSomething(foo);
setTimeout(() => {
console.log("hey");
});
console.log("after");
Current knowledge:
The callback of doSomething is not an asynchronous operation so it is not placed in the callback queue. However, the setTimeout is an asynchronous operation and thus placed in the callback queue this. Because the callback queue is called upon after the javascript thread is finished, thus the setTimeout()
function is called last.
Questions:
- Is my current understanding correct?
- What exactly makes an operation an asynchronous operation? Is this because Javascript itself has certain operations which are asynchronous by default?
- Can you make asynchronous operations yourself in javascript without the use of built in asynchronous operations like
setTimeout()
?