Cracking the interview icebreaker question

Your time to introduce yourself is your best chance to impress and steer the conversation with your interviewer “Tell me a bit about yourself” is …

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




JAVASCRIPT EVENT LOOP

To give a little background, javascript is single threaded, which means that any process that it is asked to run only has one thread to perform this task. This is unlike many other languages and this poses a problem for javascript when it comes to processes that are reliant on returning information that takes time to get a response. Some examples of this are fetching information form a database or even a simple get/post request.

Javascript solves part of the limitations that come with being single threaded by using what is called the event loop. The event loop allows for javascript to return asynchronous operations with a single thread. Furthermore, requests can be still be performed before the initial request has been returned, which allows the ability to get functions to “wait” and then perform other tasks.

EVENT LOOP STEPS

3a. No blocking process — returns the process

3b. Blocking Process — gets delegated to a ‘thread pool’

4. When block process completes, the thread Pool prepares response to event loop. The event loop then calls the callback function and returns the response back to the client.

EXAMPLES

Here is a basic example utilizing setTimeout and consol.log()

The console would log First, Third, Second in this instance due to the setTimeout. This is possible because Javascript doesnt get held up with the setTimeout here.

Another almost ubiquitous example of the elegance of the event loop, is the event listening functionality, which essentially runs a asynchronous function which waits for a ‘click’ event in order to fire off its callback.

There are some great resources online for this, which I will link to here.

Add a comment

Related posts:

Something Dear

My current existence in a peaceful residence since I was born had left me prone to be exposed to progressive changes. Changes are everywhere; friends started to move out, relationships were falling…

Why More People Need to Keep Questioning

Things around us aren’t always what they seem. As many of us have come to realize, everything is a matter of perception. Humans like to understand the world they live in, based on their our own…

Fighting to stay properly accepted

Friends and family are usually kind and considerate when engaging with older people. But there is no doubt that older people are identified as such and have to get used to the “Seniors” label. It…