Advanced JavaScript Interview Questions

Javascript logo

A mid to senior frontend developer is expected to answer most if not all of these advanced javascript questions in some detail.

What is asynchronous programming and why is it important in JavaScript?

Synchronous programming means that code is executed sequentially from top-to-bottom, blocking on long-running tasks such as network requests and disk I/O.
Asynchronous programming means that the engine runs in an event loop. When a blocking operation is needed, the request is started, and the code keeps running without blocking for the result.When the response is ready, an interrupt is fired, which causes an event handler to be run, where the control flow continues.In this way, a single program thread can handle many concurrent operations.

Everything we do in a browser from clicking buttons to making network requests, is essentially asynchronous in nature. Since JavaScript is a single-threaded language, asynchronous programming is its core competency as it is what enables it to be so efficient in handling UI and Web Application code while remaining lightweight enough to ship with every browser and not waste CPU memory.

What are two-way data binding and one-way data flow, and how are they different?

Two-way data binding means that UI fields are bound to model data dynamically such that when a UI field changes, the model data changes with it and vice-versa. This was popular in the days of MVC frameworks like AngularJS.

One way data flow means that the model is the single source of truth for the application. Changes in the UI trigger actions that signal user intent to the model or “store”. Only the model has the access to change the app’s state. The effect is that data always flows in a single direction, which makes it easier to understand. This is the default functionality of React and is the basis of Redux architecture as well.

One way data flows are deterministic, whereas two-way binding can cause side-effects which are harder to follow and understand.

At the moment, the frontend community has settled around the unidirectional (on-way) flux pattern and redux like libraries for application state management.

Show Comments