Explain JS threading and useState vs useRef

Quick Overview

This question evaluates understanding of JavaScript's execution model and concurrency mechanisms (including worker-based threading) along with React state-management semantics, specifically the behavioral differences between useState and useRef.

Explain JS threading and useState vs useRef

Company: OpenAI

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: hard

Interview Round: HR Screen

Answer the following conceptual questions about JavaScript and React: 1. **JavaScript and multithreading** - How does JavaScript's execution model work in the browser or Node.js? - Is JavaScript itself multithreaded? If not, how does it achieve concurrency? - What mechanisms (if any) exist to use multiple threads (e.g., Web Workers or worker threads), and what are their limitations? 2. **React `useState` vs `useRef`** - What is the purpose of the `useState` hook, and how does it behave with respect to component re-renders? - What is the purpose of the `useRef` hook? How is its behavior different from `useState`? - In what situations would you choose `useState` vs `useRef`? Give a few concrete examples. Explain in enough detail that a junior engineer could understand the key differences and trade-offs.

Quick Answer: This question evaluates understanding of JavaScript's execution model and concurrency mechanisms (including worker-based threading) along with React state-management semantics, specifically the behavioral differences between useState and useRef.

|Home/Software Engineering Fundamentals/OpenAI
OpenAI logo
OpenAI
Dec 6, 2025, 12:00 AM
hardSoftware EngineerHR ScreenSoftware Engineering Fundamentals
10
0

Answer the following conceptual questions about JavaScript and React:

  1. JavaScript and multithreading
    • How does JavaScript's execution model work in the browser or Node.js?
    • Is JavaScript itself multithreaded? If not, how does it achieve concurrency?
    • What mechanisms (if any) exist to use multiple threads (e.g., Web Workers or worker threads), and what are their limitations?
  2. React useState vs useRef
    • What is the purpose of the useState hook, and how does it behave with respect to component re-renders?
    • What is the purpose of the useRef hook? How is its behavior different from useState ?
    • In what situations would you choose useState vs useRef ? Give a few concrete examples.

Explain in enough detail that a junior engineer could understand the key differences and trade-offs.

Loading comments...