
Data Fetching & API
fetch API, axios, async/await, error handling, loading states, abort controllers
1What does the fetch() method return when called?
What does the fetch() method return when called?
Answer
fetch() returns a Promise that resolves with a Response object. Unlike axios, fetch does not automatically reject HTTP errors (like 404 or 500), so it's necessary to check response.ok before parsing the data. This approach gives more control over error handling but requires explicit status checking.
2How to extract JSON data from a Response object obtained with fetch()?
How to extract JSON data from a Response object obtained with fetch()?
Answer
The Response object has a json() method that returns a Promise resolving with the parsed data. This method is asynchronous because it reads the response body progressively. It's important to first check response.ok before calling json() to ensure the request succeeded.
3Which property of the Response object allows checking if the HTTP request succeeded?
Which property of the Response object allows checking if the HTTP request succeeded?
Answer
The response.ok property returns true if the HTTP status code is between 200 and 299, indicating a successful response. This property is essential because fetch() doesn't automatically reject HTTP errors, unlike axios. Checking response.ok before processing data is a best practice to avoid parsing error responses.
Which keyword allows waiting for a Promise to resolve synchronously in an async function?
In what order should the following methods be called during a fetch(): json(), then(), catch()?
+17 interview questions
Other React / Next.js interview topics
JavaScript Essentials
React Fundamentals
React Hooks
Component Lifecycle
React Router
State Management with Context
Forms & Controlled Components
React Query (TanStack Query)
Styling & CSS-in-JS
Next.js Fundamentals
TypeScript with React
Next.js Data Fetching
Next.js Server Actions
Next.js Routing & Navigation
Next.js API Routes
Next.js Metadata & SEO
Next.js Middleware & Auth
React Testing
Zustand State Management
React Performance Optimization
Error Boundaries & Error Handling
Advanced React Patterns
Next.js Advanced Features
Next.js Deployment & Production
Architecture & Design Patterns
React Server Components
Next.js Internationalization
React Security & Best Practices
Master React / Next.js for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free