Real-Life Front-End Challenges: Mid-Level Interview Questions

Irmak Esin
8 min readJan 20, 2025

--

This set of interview questions is designed for mid-level front-end developers, focusing on real-world scenarios encountered in actual projects. The aim is to evaluate candidates’ problem-solving abilities, hands-on experience, and their understanding of core concepts like React, JavaScript, state management, performance optimization, API integration, and modern front-end best practices.

Each question reflects practical challenges, encouraging candidates to think critically and demonstrate their ability to implement effective solutions in complex, real-life applications.

  1. Performance Problem While Loading Large Data
    Scenario (Question):
    Based on a scenario where a project sends a very large JSON dataset to the client at once, leading to extremely long initial page load times, how would you approach optimizing data loading to improve performance and user experience?

Explanation:

  • Lazy loading: Instead of fetching all data at once, retrieve data in parts when needed (e.g., when the user scrolls or interacts). This reduces initial load time.
  • Pagination: Splitting large data sets into pages and only loading the relevant page can improve both performance and user experience.
  • Code splitting: In larger applications, avoid bundling all modules for the initial load. Load them dynamically as the user navigates (reduces initial bundle size).

2. Real-Time Form Submission Causing Performance Issues
Scenario (Question):
In an e-commerce application, a multi-field form sends a request to the backend on every keystroke. This overloads the server, increasing response times, and causes lags in the user interface. How would you optimize this?

Explanation:

  • Apply Debounce or Throttle: Reduce unnecessary requests by waiting for a specific period after keystrokes (debounce) or sending requests at defined intervals (throttle).
  • Batch Updates: Combine multiple input changes into a single request to the server.
  • Local Validation: Perform as much validation as possible on the client side before sending requests to the server.
  • Asynchronous Optimization: Use optimistic updates to keep the UI responsive and handle server requests in the background if necessary.

3. Slow Page Loads Due to Large Image Files
Scenario (Question):
We have high-resolution product images on our site, which significantly slow down page load times. Some users leave before images fully load. How can we tackle this?

Explanation:

  • Lazy loading (images): Only load images when they’re about to enter the viewport, improving initial load times.
  • Image Optimization: Using more efficient formats (WebP, AVIF) and compressing files can greatly reduce image size.
  • Responsive Images: Serve different image sizes or formats based on device or screen size for optimal performance and clarity.

4. Complex Data Sharing Across Components
Scenario (Question):
In a React project, prop drilling has become excessive. We pass data through multiple intermediate components, making the codebase hard to maintain. How would you approach this?

Explanation:

  • Context API: Provides a way to pass data directly to relevant components without manually drilling through props at every level.
  • State Management Libraries: For more complex data or larger projects, a single source of truth (e.g., Redux store) can be more organized.
  • Local vs. Global: Not all state should be global. Use local state where possible, and only put necessary shared data in context or global state.

5. Re-render Issue
Scenario (Question):
In your React application, you’re passing a function as a prop to a child component. Because this function is recreated on every render, the child component re-renders frequently. How can you prevent this?

Explanation:

  • Wrap the function in useCallback so that it retains the same reference unless its dependencies change.
  • This prevents unnecessary re-renders of the child component.
  • Alternatively, defining the function outside the parent component or reducing inline creation can also help.

6. Avoiding Style Conflicts with Global CSS in Large Applications
Scenario (Question):
Your project uses a global.css file, but as new features are added, existing global styles start to affect some components. How would you prevent such style conflicts when working with global CSS?

Explanation:

  • Utility-First Approach: Adopt a utility-first approach (e.g., TailwindCSS) to minimize reliance on global CSS and focus on component-specific styles.
  • CSS Namespace: Use a consistent naming convention (e.g., .app-header, .app-footer) to ensure global styles do not unintentionally affect unrelated components.
  • Avoid Overly Specific Selectors: In global CSS, avoid overly specific selectors (div p span) and stick to minimal and clear rules to reduce conflicts.

7. Writing a Custom Hook
Scenario (Question):
You need to reuse the same logic across multiple components. How would you create a custom hook for this, and what considerations should you keep in mind?

Explanation:

  • Consolidate repetitive functionality in a function prefixed with use (e.g., useFetchData).
  • Manage state, effects, and any cleanup inside the hook.
  • Carefully design the hook’s dependency array, returned values, and side effects to ensure predictable behavior.

8. Event Bubbling & Capture
Scenario (Question):
Clicking a form element triggers a parent-level event handler, causing unwanted behavior. How do you control this situation?

Explanation:

  • Use e.stopPropagation() to halt event bubbling.
  • Understand the capturing and bubbling phases to intervene at the correct point.
  • Sometimes e.preventDefault() is also needed, for example, to stop default form submission.

9. Memory Leaks in React
Scenario (Question):
You notice that some event listeners or intervals continue running even after a React component has unmounted, causing memory leaks. How can you prevent this?

Explanation:

  • Use the cleanup function (return) in useEffect to remove event listeners or clear intervals.
  • Perform all necessary cleanup during component unmount.
  • If using third-party libraries, be sure to call their “destroy” or “unsubscribe” methods as needed.

10. SSR vs. CSR
Scenario (Question):
How do you decide between SSR (e.g., Next.js) and a classic CSR approach for a React project? What are the main criteria?

Explanation:

  • SEO: SSR can provide immediate content for search engines to index.
  • Performance: SSR often improves initial paint time on slow devices.
  • Project Complexity: SSR adds extra server and configuration overhead, so for simpler projects, CSR might suffice.

11. Debounce vs. Throttle
Scenario (Question):
While typing into an input field, an API call is triggered on every keystroke. You want to improve performance using debounce or throttle. Which one do you choose and when?

Explanation:

  • Debounce: Fires the call only after the user has stopped typing for a set duration (useful for search inputs).
  • Throttle: Fires the call at fixed intervals (e.g., once per second), useful for continuously updating metrics like window resizing.
  • The choice depends on whether you need to prioritize accuracy (debounce) or speed (throttle).

12. Handling Side Effects in Redux
Scenario (Question):
When updating data in a Redux store, how do you handle async requests or other side effects? What approaches do you use?

Explanation:

  • Redux Thunk: A good starting point for simple scenarios, allowing actions to be async functions.
  • Redux Saga: Powerful for more complex flows, cancellations, and parallel requests.
  • Redux Toolkit: Has built-in support for thunk, while still allowing advanced middleware like Saga if needed.

13. Managing Increasingly Complex State and Data Consistency
Scenario (Question):
Your front-end application has grown significantly, and the amount of shared state across pages has increased. Managing local state (using React hooks like useState or useReducer) has become overly complex, and inconsistencies in data are starting to appear. How would you address this issue to make state management more sustainable and ensure data consistency?

Explanation:

  • Adopt Global State Management: Use tools like Context API for lightweight state sharing or Redux for larger applications where state is deeply nested or shared across many components.
  • Normalize the State Structure: Store data in a flat structure to make updates predictable and avoid deeply nested state trees.
  • Server State Synchronization: For data fetched from APIs, use tools like TanStack Query to manage server-side data caching and synchronization. This avoids inconsistencies caused by stale data.
  • Implement Modular State Logic: Divide state into slices or contexts to manage specific features independently while maintaining global access where needed

14. Keeping User Data Consistent Across Pages
Scenario (Question):
In your application, users can edit their profile information (e.g., name, age, address) on a profile page, and this data is also displayed on a list page. Users expect their changes to immediately reflect everywhere. How would you manage and synchronize this data across multiple components and pages to ensure consistency?

Explanation:

  • Centralize Data Storage: Use a global state management tool like Context API or Redux to store user data. This ensures updates in one part of the app automatically reflect elsewhere.
  • Optimistic Updates: Update the state locally immediately after user actions to make the UI responsive. Synchronize with the server in the background and revert changes if the server update fails.
  • Invalidation and Refetching: For data displayed in lists or dynamically loaded pages, invalidate and refetch the server data after updates to ensure consistency.
  • Modular State Sharing: If certain components require frequent updates, pass data via props or context to avoid unnecessary re-renders of unrelated components.

15. Managing User Sessions and Data Persistence
Scenario (Question):
You need to store a user’s session information (e.g., a token) in the browser to keep them logged in when they refresh the page or reopen the application. How would you implement this while balancing security and performance considerations?

Explanation:

  • Use Local or Session Storage: Store tokens in localStorage for persistence across browser sessions or sessionStorage for single-session storage.
  • HttpOnly Cookies: For sensitive data like tokens, prefer storing them in HttpOnly cookies to reduce exposure to XSS attacks.
  • Token Expiry Handling: Include token expiry information and refresh tokens to manage session validity without requiring frequent logins.
  • Secure Communication: Always use HTTPS for token transmission and ensure secure cookie flags are set to protect against attacks.
  • Revalidation Mechanisms: Implement a token revalidation mechanism on app initialization to check if the session is still valid and update it if necessary.

16. Routing with Filters Persisting Across Pages
Scenario (Question):
On a page, users select filters (e.g., date range and category). After selecting the filters, they navigate to another page. However, the filters are reset on the new page, and users expect their selections to persist. How would you solve this issue?

Explanation:

  • Query Parameters: Append the selected filters as query parameters during navigation. Read and apply these parameters on the new page to update the UI.
  • Global State Management: Use global state management (e.g., Context API or Redux) to store filters so that they remain accessible across pages.
  • Persistent State: Save the filter selections in localStorage or sessionStorage to maintain them even during navigation or page reloads.

17. Implementing a Theme System Using Global CSS
Scenario (Question):
In an application, you want users to switch between light and dark themes. The themes should be applied globally across all pages. How would you implement this feature using global CSS?

Explanation:

  • CSS Variables for Themes: Define all theme-dependent styles (e.g., colors, typography) as CSS variables, and update their values based on the selected theme.
  • Theme Control via html or body: Use a class on the html or body tag (e.g., class="dark-theme") to toggle between themes and apply the respective styles.
  • Persist User Preference: Save the user’s theme selection in localStorage and apply it when the app reloads to maintain consistency.

--

--

Irmak Esin
Irmak Esin

Written by Irmak Esin

🖥️ Front-End Developer | Interested in React & JavaScript

No responses yet