Let's heat our coffee using setTimeout() in JS

Let's heat our coffee using setTimeout() in JS

If you love your hot coffee, you don't wanna have it to be served cold.
And there are times when you make your cup of coffee and keep it as it is on your working desk, without having even a single sip.


So, we decide to heat it quickly, rather than drinking it at room temperature.
Okay. I know it's not a big deal to do that. But, what if your microwave asks you to set the timer using JavaScript?
Of course, it also gets bored by doing the same task frequently.
Well, Okay! Let's do it!



Now, to perform the task, our microwave just needs to write the code for the timeout of heating our coffee.
The rest of the things like setting minimum temperature and staring to heat will be done by itself, as soon as we set the timeout.
Why and how? Because our microwave is our kind friend.



Okay! Let's write the code snippet for it.

First, we add a function named HeatCoffee and log a message that our coffee will get heated in 20 seconds.


const HeatCoffee = () => { 
console.log('Your Coffee will be ready in less than 20s 👍');
};
HeatCoffee();

Then, we will add the setTImeout() inside HeatCoffee() to set the timeout for 20 seconds.


const HeatCoffee = () => { 
console.log('Your Coffee will be ready in less than 20s 👍');
    {
        setTimeout(() => {
        console.log('Hey 🙌 Your coffee is ready ☕️')
        }, 20000);
     }

};
HeatCoffee();

Hurray! We have won our hot coffee.
🙌 Enjoy!
☕️

You can read the document on Concurrency model and event loop in javascript through the link below. 👇🏼

developer.mozilla.org/en-US/docs/Web/JavaSc..

Also, don't forget to say thanks to your microwave. 😇