16
loading...
This website collects cookies to deliver better user experience
var message = "Hello World!";
const send = function (message) {
const log = `"${message}" sent to the reciever`;
console.log(log);
};
send(message);
<anonymous>
in the browser's console.alert()
and press enter.console.log("Fetching Data");
function sayHello() {
console.log("JS says Hello!");
}
function fetchDatabase() {
console.log("Data Retrieved");
}
setTimeout(() => {
fetchDatabase();
}, 3000);
sayHello();
console.log("Meanwhile doing some other task...");
Fetching Data
JS says Hello!
Meanwhile doing some other task...
Data Retrieved
setTimeout()
and delegated the task of fetching from the database.sayHello()
function gets pushed on to the Call Stack and the second statement gets printed and sayHello()
is popped off the stack.setTimeout()
simulated a long running task of fetching from database and the asynchronous nature of the runtime made the code Non-blocking.Keep Learning and Keep Growing 🎉