What is the difference between blocking and non-blocking calls in JavaScript?
During an interview for a senior software engineer's position, you will be asked about many different technologies used in the job. Some of these questions will ask you to compare two different technologies which are similar but have different functions or outcomes. Demonstrating your knowledge of these differences will impress the interviewer and satisfy their curiosity about your understanding of the topic.
"The key difference between blocking and non-blocking calls in JavaScript is that the first one is a synchronous operation and the other is asynchronous. Blocking calls require JavaScript operations to wait until a non-Javascript operation provides input or output or finishes its execution. Non-blocking JavaScript calls can execute operations synchronous with other pieces of the script. It is important to know this since JavaScript is a single-threaded executable and can only execute code in a specific order, waiting for the previous operation to be completed before it starts the next one. Executing non-blocking calls overcomes this limitation and helps programs run faster."
When responding to a question like this, start by defining each term, then briefly compare them, stating their features and benefits. Quickly contrast them, stating how they differ, and finish by possibly providing an example to illustrate your answer. This methodology will allow you to organize your answer for any question asking you to compare two terms or technologies.
Community answers are written by other candidates practicing this set. Reading how others frame the same question is one of the fastest ways to sharpen your own.
Anonymous Answer
A blocking call is otherwise known as a synchronous operation and a non-blocking call is an asynchronous operation. A synchronous JavaScript operation waits for another process to finish before moving on to the next part of the code. An asynchronous operation does not wait for the operation to finish and instead proceeds on with the rest of the code execution. In the early days of JavaScript, callbacks were used in frameworks like Ajax to replicate synchronous-like behavior and would provide the operation with a callback function to be executed once the process was complete. Later on, Promises were introduced to JavaScript which allowed for an executable call chain to be defined in a synchronous order with a catch statement at the end of the chain. And more recently, the async-await functionality was added to JavaScript that allows you to easily specify any section of code that must be executed synchronously.
Amanda's Feedback
Excellent! You've explained the difference between blocking and non-blocking calls simply and clearly. Consider expanding this answer to specify when or how you typically use each, showing the interviewer that you not only understand the functionality but when each is best used.
Unlock all 47 Senior Software Engineer questions
Unlock expert responses to system design and leadership questions interviewers expect.
Get Started