learn deep. ship safe.Practice testsFollow ByteMunSubscribe
React · Fresher

React Interview Questions for Freshers

12 React interview questions for freshers and students (0 to 1 year): JSX, props, useState, conditional rendering, controlled inputs, effects and Fragments. Each answer explains why the other options are wrong.

CoversEffectsFormsHooksJsxPropsReactRenderingStateStyling

By Published Answers checked by Deepak

Take it as a timed test

  • 12 questions
  • 15 min
  • Pass mark 60%
  • Answers shown at the end
Start the timed test

No sign-up. Your answers and scores stay in this browser.

This freshers paper has 12 React questions for freshers and students with roughly 0 to 1 year of experience. It covers JSX, props, useState, conditional rendering, controlled inputs, effects and Fragments. Ten questions are on this page with full explanations; the timed test also includes two questions that aren't shown here, so practise for understanding rather than memory.

How should you use this paper?

Answer each practice question before opening its explanation, and say your reasoning out loud the way you would in an interview. Then take the timed test: 15 minutes, a pass mark of 60%, with answers shown at the end. Your report breaks your score down by topic and difficulty, and you can retry only the questions you missed.

Practice questions with answers

Try each one before opening the answer. The explanation covers why the other options are wrong. The timed test also uses 2 questions that aren't shown here, so practise for understanding, not memory.

Q1Choose one answereasy

What is JSX?

  1. A syntax that looks like HTML and is compiled into JavaScript function calls that create React elements
  2. A separate templating language that runs in the browser
  3. A CSS-in-JS library
  4. A JSON format for describing components
Show answer and explanation

Answer: A. A syntax that looks like HTML and is compiled into JavaScript function calls that create React elements

JSX is syntax sugar. A compiler such as Babel, SWC or esbuild turns <h1 className="t">Hi</h1> into a call like jsx('h1', { className: 't', children: 'Hi' }), which returns a plain object describing the UI. That's why attributes use JavaScript names like className and htmlFor, and why you can embed any expression inside { }.

Q2Choose one answereasy

Can a child component change the props it receives?

  1. No: props are read-only; the parent changes them, or passes a callback the child can call
  2. Yes, by assigning to props.value
  3. Yes, but only inside useEffect
  4. Only if the prop is an object
Show answer and explanation

Answer: A. No: props are read-only; the parent changes them, or passes a callback the child can call

Props flow one way, from parent to child, and React treats them as read-only. To change something the parent owns, the parent passes a function such as onChange, and the child calls it; the parent updates its state and re-renders with new props. Mutating a prop object directly leads to UI that doesn't update and bugs that are hard to trace.

Q3True or falsemedium

Calling a useState setter with an object merges it into the old state object, like class components' setState.

TrueFalse

Show answer and explanation

Answer: False

False. The useState setter replaces the value completely. If state is { name, email } and you call setUser({ name: 'Ana' }), the email is gone. Spread the old value in yourself: setUser(u => ({ ...u, name: 'Ana' })). Or keep unrelated values in separate useState calls, or use useReducer for complex objects.

Q4Choose one answermedium

With const count = 0, what does <div>{count && <p>Items</p>}</div> render?

javascript
const count = 0;
return <div>{count && <p>Items</p>}</div>;
  1. A div containing the text "0"
  2. An empty div
  3. A div with the paragraph "Items"
  4. Nothing at all
Show answer and explanation

Answer: A. A div containing the text "0"

&& returns its left side when that side is falsy, so the expression evaluates to 0. React doesn't render false, null or undefined, but it does render numbers, so a stray 0 appears on the page. Make the condition a real boolean: {count > 0 && ...}, or use a ternary.

Q5Choose one answereasy

What makes an input a controlled component?

  1. Its value comes from state and every change goes through an onChange handler that updates that state
  2. It has a ref attached
  3. It uses defaultValue
  4. It's inside a <form>
Show answer and explanation

Answer: A. Its value comes from state and every change goes through an onChange handler that updates that state

In a controlled input, React state is the single source of truth: value={name} plus onChange={e => setName(e.target.value)}. That makes validation, formatting and resetting easy. An uncontrolled input keeps its own value in the DOM, set initially with defaultValue and read with a ref or FormData, which is simpler for basic forms.

Q6Choose one answermedium

When does useEffect(fn, []) run?

  1. After the first render is shown on screen; in development with StrictMode, React runs it, cleans up, and runs it again once
  2. Before the first render
  3. After every render
  4. Only when the component unmounts
Show answer and explanation

Answer: A. After the first render is shown on screen; in development with StrictMode, React runs it, cleans up, and runs it again once

An empty dependency array means the effect has nothing to re-sync on, so it runs once after the component mounts and its cleanup runs on unmount. In development, StrictMode deliberately mounts, unmounts and remounts each component once to surface effects without proper cleanup, so you'll see it run twice there but only once in production.

Q7Select all that applyeasy

Which of these are valid ways to style a React element? Select all that apply.

  1. className="card"
  2. style={{ color: 'red' }}
  3. A CSS Module: className={styles.card}
  4. style="color: red" as a string
Show answer and explanation

Answer: A. className="card" + B. style={{ color: 'red' }} + C. A CSS Module: className={styles.card}

React uses className because class is a reserved word in JavaScript. The style prop takes an object with camelCase properties, such as { backgroundColor: 'red' }, not a CSS string; passing a string throws an error. CSS Modules scope class names to the component, and frameworks like Tailwind also just set className.

Q8Choose one answereasy

Two sibling components need to show and change the same value. What is the standard approach?

  1. Lift the state up to their closest common parent and pass it down as props
  2. Give each sibling its own copy and sync them with useEffect
  3. Store it in a global variable
  4. Use refs to read each other's state
Show answer and explanation

Answer: A. Lift the state up to their closest common parent and pass it down as props

React data flows down, so shared state belongs in the nearest component above both siblings. The parent holds it with useState and passes the value and an updater function to each child. Copying state into two places and syncing with effects causes extra renders and bugs. For values needed far down the tree, context avoids passing props through many levels.

Q9Match each item on the lefteasy

Match each React hook to when you'd reach for it.

  1. useState
  2. useEffect
  3. useRef
  4. useContext
  • Syncing with something outside React, like a subscription
  • Reading a value provided higher up the tree
  • A value that changes and should update the screen
  • A reference to a DOM element, such as to focus an input
Show answer and explanation

Answer: useState → A value that changes and should update the screenuseEffect → Syncing with something outside React, like a subscriptionuseRef → A reference to a DOM element, such as to focus an inputuseContext → Reading a value provided higher up the tree

useState holds render-affecting data. useEffect is for side effects that sync with the outside world: subscriptions, timers, imperative widgets. It isn't for deriving values from props, which you can compute during render. useRef holds a mutable value or DOM node without re-rendering, and useContext reads from the nearest provider.

Q10Choose one answereasy

Why use <>...</> (a Fragment)?

  1. To return several elements from a component without adding an extra DOM element
  2. To make the component render faster
  3. To mark code that only runs on the server
  4. To create a new state scope
Show answer and explanation

Answer: A. To return several elements from a component without adding an extra DOM element

A component must return a single node, and wrapping siblings in a div adds markup that can break layouts, such as table rows or flex children. A Fragment groups them without adding anything to the DOM. Use the long form <Fragment key={id}> when you need a key, for example when mapping a list to pairs of elements.

Answered them all? Take the same questions against the clock and get a topic-by-topic report.

Start the timed test

More React quizzes

All React quizzes →

Senior5+ years

Advanced React Interview Questions

12 React interview questions for senior and lead developers (5+ years): Server Components, useActionState, useOptimistic, the React Compiler, hydration, transitions and virtualisation. Each answer explains why the other options are wrong.

Test
12 Qs
Time
18 min
Practice
10 Qs