Interview questions

JavaScript interview questions

Runtime behaviour, async code and language fundamentals.

JavaScript

How does the JavaScript event loop work?

JavaScript runs your code on a single call stack. Asynchronous work such as timers, network requests and I/O is handled by the host environment, and its callbacks wait in queues. The event loop moves a callback onto the stack only when the stack is empty, always draining the microtask queue (promises) before taking the next macrotask (timers, events).

JavaScript

What is a closure in JavaScript?

A closure is a function bundled with the variables from the scope where it was created. The inner function keeps access to those variables even after the outer function has returned. Closures power private state, function factories, memoisation and callbacks, and explain classic bugs such as loops that capture a shared variable.

JavaScript

What is the difference between promises and async/await?

They are the same mechanism with different syntax. A promise represents a value that will be available later and is consumed with then and catch. async/await is syntax built on promises: an async function always returns a promise, and await pauses that function until a promise settles, letting asynchronous code read like synchronous code with try/catch error handling.

JavaScript

What are the differences between var, let and const, and what is hoisting?

var is function-scoped and hoisted with an initial value of undefined. let and const are block-scoped and also hoisted, but they sit in a temporal dead zone until their declaration runs, so accessing them early throws a ReferenceError. const prevents reassignment of the binding, not mutation of the object it points to.

Walk into your next interview prepared

Start free, install the Windows app and run a practice session today.

JavaScript Interview Questions & Answers | Ask Agents