JavaScript Interview

Promises, Async/Await, Fetch & Modern JavaScript

JavaScript interview questions covering callbacks, Promises, async and await, Promise combinators, Fetch API, HTTP handling, modules and modern asynchronous JavaScript.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
76
Mid-LevelIntermediate

What is a callback function in JavaScript?

A callback is a function passed to another function so it can be executed later or as part of that function's operation. Callbacks are fundamental to JavaScript APIs such as event handling, timers, array methods, and asynchronous operations.

77
Mid-LevelIntermediate

What is callback hell?

Callback hell describes deeply nested callback-based asynchronous code that becomes difficult to read, maintain, test, and handle errors in. It often appears when each asynchronous operation depends on the result of the previous operation.

78
Mid-LevelIntermediate

What is a Promise in JavaScript?

A Promise is an object representing the eventual completion or failure of an asynchronous operation. It allows code to register handlers for a future result instead of nesting callbacks.

79
Mid-LevelIntermediate

What are the states of a Promise?

A Promise starts as pending. It becomes fulfilled when the operation succeeds and resolve is used, or rejected when the operation fails and reject is used.

80
Mid-LevelIntermediate

How do then(), catch(), and finally() work with Promises?

then registers handlers for successful Promise results and returns a new Promise, enabling chaining. catch registers a rejection handler and is effectively a convenient way to handle errors from the preceding chain.

81
Mid-LevelIntermediate

What is Promise chaining?

Promise chaining connects asynchronous operations by returning a value or another Promise from a then callback. Each subsequent then receives the resolved result of the previous stage.

82
Mid-LevelIntermediate

What is async/await in JavaScript?

async/await is syntax built on top of Promises that allows asynchronous code to be written in a more sequential style. An async function always returns a Promise.

83
Mid-LevelIntermediate

Does an async function always return a Promise?

Yes. Calling an async function always returns a Promise. If the function returns an ordinary value, JavaScript fulfills the returned Promise with that value.

84
Mid-LevelIntermediate

How do you handle errors with async/await?

Use try/catch around awaited operations when the function should handle a rejection locally. The catch block receives the thrown rejection reason, which is commonly an Error object.

85
Mid-LevelIntermediate

What is the difference between sequential and parallel asynchronous operations?

Sequential code waits for one independent operation to finish before starting the next, increasing total latency. Parallel initiation starts independent operations before waiting for their combined results.

86
Mid-LevelIntermediate

What does Promise.all() do?

Promise.all accepts an iterable of values or Promises and returns a Promise that fulfills when all inputs fulfill. The fulfilled result is an array preserving the input order.

87
Mid-LevelIntermediate

What does Promise.allSettled() do?

Promise.allSettled waits until every supplied Promise has settled, whether fulfilled or rejected. It returns an array of result objects containing a status and either a value or reason.

88
Mid-LevelIntermediate

What is the difference between Promise.race() and Promise.any()?

Promise.race settles as soon as the first input Promise settles, whether that first result is fulfillment or rejection. Promise.any fulfills as soon as any input fulfills and ignores earlier rejections while a possible fulfillment remains.

89
Mid-LevelIntermediate

How does fetch() work in JavaScript?

fetch starts an HTTP request and returns a Promise that fulfills with a Response object when an HTTP response is received. The response body can then be read with methods such as json, text, blob, or arrayBuffer.

90
Mid-LevelIntermediate

How do you send a POST request with fetch()?

Pass an options object containing method, headers, and body. When sending JSON, set Content-Type to application/json and serialize the JavaScript value with JSON.stringify.

91
Mid-LevelIntermediate

How can you cancel a fetch request?

Use AbortController. Pass the controller's signal to fetch, then call controller.abort when the request should be canceled.

92
Mid-LevelIntermediate

What is JSON, and how do JSON.parse() and JSON.stringify() work?

JSON is a text data format commonly used for API communication and storage. JSON.stringify converts supported JavaScript values into JSON text, while JSON.parse converts valid JSON text into a JavaScript value.

93
Mid-LevelIntermediate

What is optional chaining (?.)?

Optional chaining safely accesses a property, element, or method when the value to the left may be null or undefined. If that value is nullish, evaluation stops and the expression returns undefined instead of throwing a property-access error.

94
Mid-LevelIntermediate

What is the nullish coalescing operator (??)?

The nullish coalescing operator returns its right-hand operand only when the left-hand operand is null or undefined. Values such as 0, false, and an empty string are preserved.

95
Mid-LevelIntermediate

What is the difference between || and ?? for default values?

The logical OR operator returns the right operand when the left operand is falsy. Nullish coalescing returns the right operand only when the left operand is null or undefined.

96
Mid-LevelIntermediate

What are ES modules in JavaScript?

ES modules are the standardized JavaScript module system based on export and import syntax. Modules let applications split code into reusable files with explicit dependencies.

97
Mid-LevelIntermediate

What is the difference between named exports and default exports?

A module can have multiple named exports, which are imported using their exported names unless aliases are used. A module can also have one default export, which the importing module may bind to a locally chosen name.

98
Mid-LevelIntermediate

What is dynamic import()?

Dynamic import() loads a module asynchronously and returns a Promise for the module namespace object. Unlike a static import declaration, it can be invoked conditionally at runtime.

99
Mid-LevelIntermediate

What is strict mode in JavaScript?

Strict mode enables a stricter set of JavaScript runtime rules that convert some silent mistakes into errors and change certain legacy behaviors. It can be enabled for classic scripts or individual functions with "use strict".

100
Mid-LevelIntermediate

What are the main best practices for modern asynchronous JavaScript?

Prefer Promises and async/await for asynchronous control flow, and use try/catch or explicit Promise rejection handling at appropriate boundaries. Run independent I/O concurrently when it improves latency, but do not start uncontrolled amounts of work without considering resource limits.