Front-End Mock Interview: JavaScript and React Practice
Introduction
In the last lesson of chapter 9, run a front-end mock interview with an algorithm exercise and a React component exercise. Practice with a partner or on your own, then use the review to decide what to revisit across the Meta Front-End Developer pathway.
OnLevelUp wrote these independent practice problems. The official ninth course covers interview communication, pseudocode, data structures, and algorithms. Consult Coursera for the requirements of the Meta credential. Official course (opens in a new tab) · Certificate program (opens in a new tab)
Learning objectives
By the end of this lesson you can:
- Run a timed practice interview with a clear structure and self-assessment.
- Solve a coding problem and a front-end component problem while explaining your reasoning.
- Answer common behavioral and technical-communication prompts with a structured answer.
- Discuss trade-offs, testing, accessibility, and performance for an interface solution.
- Receive feedback gracefully and iterate on your own solution.
- Review your readiness across the nine areas of the pathway and plan your next steps.
1. Structure a front-end mock interview
Set a practice agenda you can complete in one sitting. Adjust it to the actual employer's instructions when preparing for a specific interview.
| Part | What to practice | Suggested time |
|---|---|---|
| Introduction and background | Communication, motivation, project experience | 5 min |
| Coding problem | Problem solving, data structures, algorithms, clean code | 30 min |
| Front-end or UI problem | React skills, accessibility, and state design | 30 min |
| Your questions | Ask about the team's work and expectations | 5 min |
Practice clarifying, thinking aloud, working with hints, and testing alongside the code.
2. Communication toolkit
Use short, repeatable phrases:
- Clarify: "Let me restate the problem to make sure I understand. Inputs are…, output is…. Is that right?"
- Plan: "The prefix scan takes quadratic time in the worst case. A Map can reduce that to expected linear time under a hash-table model."
- Narrate: "I'm going to keep two indexes, one per end."
- Test: "Let me trace the empty input and a one-item input."
- Reflect: "The trade-off is memory for speed. If the list were huge, I'd consider…"
- Recover: "I see a bug: the index stops one early. Fixing the loop condition."
Structured answers: STAR for behavioral questions
For "Tell me about a time…" prompts, use STAR:
- Situation: the context in one or two sentences.
- Task: your responsibility or the goal.
- Action: what you did, in specific steps.
- Result: the outcome, ideally measurable, and what you learned.
Fictional example for “Describe a time you handled a disagreement in a team.” Use evidence from your own work when answering. S: In my capstone group, two of us wanted different filter designs. T: I owned the catalog page and had to decide with a week left. A: I wrote a short comparison of both options against the acceptance criteria, built a 30-minute prototype of each, and asked a classmate to try both. R: The URL-based filter won because testers could share links; we shipped on time, and I now compare options against criteria before arguing about taste.
3. Practice interview, part A: coding problem
Set a timer for 30 minutes. Write on paper or in a plain editor, without running code first. Follow the five steps from lesson 1.
Problem A (original)
Harbor Workshops logs each page view as an object { userId, page }, in time order. A "journey" is the sequence of pages one user visited. Write firstRepeatedPage(views, userId) that returns the first page that the given user visited for the second time, or null if there is none.
Example:
views = [
{ userId: 'u1', page: '/home' },
{ userId: 'u2', page: '/home' },
{ userId: 'u1', page: '/workshops' },
{ userId: 'u1', page: '/home' },
{ userId: 'u1', page: '/workshops' },
]
firstRepeatedPage(views, 'u1') -> '/home'A model walk-through
Clarify. Is the log sorted by time? (Yes.) Can the same page appear in other users' entries? (Yes, ignore them.) Does "first repeated" mean the first page that becomes a repeat while scanning? Yes: /home repeats at index 3, before /workshops repeats at index 4.
Examples and edges. Unknown user → null. Empty log → null. One visit per page → null. Same page three times → still returns it at the second visit.
Plan. Scan once. Keep a Set of pages seen for that user. When a page is already in the set, return it. Brute force would, for each view, search all earlier views: O(n²).
Code.
function firstRepeatedPage(views, userId) {
const seen = new Set();
for (const view of views) {
if (view.userId !== userId) continue;
if (seen.has(view.page)) return view.page;
seen.add(view.page);
}
return null;
}Verify. Trace u1: /home added; u2 skipped; /workshops added; /home already present → return /home. Correct.
Complexity and follow-ups. Worst-case scan length is n views. Under the hash-table model the time is expected O(n), with O(p) working space for p distinct pages seen for the requested user. For repeated queries, scan in time order with a set per user and record each user's first repeat as soon as it occurs. A set of all pages alone loses the repeat order. This builds the index in expected O(n) time and O(n) space, and a lookup is expected O(1) under the same model. A stream avoids storing the entire log. Exact detection still needs membership state for the distinct pages seen, which can grow until you move that state to durable storage or limit the input.
Alternative costs. Repeating a linear membership scan over an ever-growing journey can take O(n²). If you sort by page, preserve the original positions and compare second occurrences to recover the chronological answer.
4. Practice interview, part B: front-end problem
Set another 30 minutes.
Problem B (original)
Build a SeatPicker React component with seats, an array of { id, label, taken } records, and max, a nonnegative integer. Seat ids are unique. During one practice round, the inventory and limit stay fixed. Show every seat as a button with a visible label, disable taken seats, and let users toggle up to max available seats. Show a selection count and call onChange(selectedIds) on each change.
A model walk-through
Clarify. The component owns its selection in this fixed-inventory exercise. Confirm the maximum and the behavior at the limit. Selected seats must remain operable so users can free a place. For a new inventory round, the parent can change the component key to reset the state. If a live app must retain valid selections while inventory changes, let the parent own both values and reconcile the selected ids and limit together.
Design the state. Store the selected ids. Derive the count, the limit flag, and the status text from the set and max. Compute the next set in the handler, then pass that same selection to state and the callback. React state structure (opens in a new tab)
Code.
// src/components/SeatPicker.jsx
import { useState } from 'react';
export function SeatPicker({ seats, max, onChange }) {
const [selected, setSelected] = useState(() => new Set());
function toggle(id) {
const next = new Set(selected);
if (next.has(id)) {
next.delete(id);
} else if (next.size < max) {
next.add(id);
} else {
return; // limit reached
}
setSelected(next);
onChange?.([...next]);
}
const limitReached = selected.size >= max;
return (
<fieldset>
<legend>Choose your seats</legend>
<p role="status">{selected.size} of {max} selected</p>
<ul className="seat-grid">
{seats.map((seat) => {
const isSelected = selected.has(seat.id);
const blocked = seat.taken || (limitReached && !isSelected);
return (
<li key={seat.id}>
<button
type="button"
aria-pressed={isSelected}
disabled={blocked}
onClick={() => toggle(seat.id)}
>
{seat.label}
{seat.taken && ' (taken)'}
</button>
</li>
);
})}
</ul>
</fieldset>
);
}Verify with a component test. Use the Vitest setup from the lesson on testing and presenting your React capstone. Revisit user-centered React component tests for role-based queries and asynchronous user actions.
// src/components/SeatPicker.test.jsx
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { expect, test, vi } from 'vitest';
import { SeatPicker } from './SeatPicker.jsx';
const seats = [
{ id: 'a1', label: 'A1', taken: false },
{ id: 'a2', label: 'A2', taken: false },
{ id: 'a3', label: 'A3', taken: false },
{ id: 'a4', label: 'A4', taken: true },
];
test('limits selection and lets the user free a place', async () => {
const user = userEvent.setup();
const onChange = vi.fn();
render(<SeatPicker seats={seats} max={2} onChange={onChange} />);
const first = screen.getByRole('button', { name: 'A1' });
const second = screen.getByRole('button', { name: 'A2' });
const third = screen.getByRole('button', { name: 'A3' });
expect(screen.getByRole('button', { name: 'A4 (taken)' })).toBeDisabled();
await user.click(first);
await user.click(second);
expect(first).toHaveAttribute('aria-pressed', 'true');
expect(third).toBeDisabled();
expect(screen.getByRole('status')).toHaveTextContent('2 of 2 selected');
await user.click(first);
expect(third).toBeEnabled();
await user.click(third);
expect(onChange).toHaveBeenLastCalledWith(['a2', 'a3']);
});Talking points interviewers value.
- Derived state: compute the display count and limit from the selected ids.
- Immutability: each successful toggle passes a new
Setto React. The previously rendered selection stays intact. - Accessibility: native buttons provide Enter and Space activation.
aria-pressedexposes the toggle state with a consistent seat label. The fieldset and legend group the buttons, the status can announce count changes, and visible text identifies taken seats. Check focus visibility, target size, and announcements in a browser. WAI-ARIA button pattern (opens in a new tab) - Keys: stable
seat.id, not the index. - Performance: the component visits all n seat records on render and copies k selected ids on a toggle. Under the hash-table model this gives expected O(n) render work and O(k) work to copy the selection and report it. Profile a representative seat map before adding memoization.
- Edge cases:
maxof zero disables every unselected seat. An empty inventory renders the group with no seat buttons. In a live inventory version, reconcile state when availability changes so stale selections cannot consume the limit.
Weaker alternatives. A div with onClick loses keyboard access. Storing count in separate state creates inconsistency bugs. Storing selection on the seat objects mutates props.
5. Part C: technical discussion questions
Practice answering these aloud in 60–90 seconds each. Sample answers are summaries to compare against, not scripts.
| Prompt | Points a strong answer covers |
|---|---|
| "Why did you choose Map over an array here?" | Lookup cost, uniqueness, trade-off in memory, immutability in React state |
| "How would you make this faster?" | Measure first, reduce repeated calculations, and evaluate rendering costs. Stable keys preserve item identity, and memoization may reduce renders under suitable conditions. |
| "How do you know your component works?" | Tests by role and name, edge cases, manual keyboard check, accessibility checks |
| "What happens if the API fails?" | Loading and error states, retry, message that is understandable, no crash |
| "Explain a React render and commit." | Rendering calls components to compute their UI. React applies the required DOM changes during commit. A render can produce no DOM update. |
| "A bug appears only in production. What do you do?" | Reproduce, check logs and network, compare environment, bisect with Git, add a test, fix, and write down the cause |
| "What would you improve in your capstone?" | Honest limits, a prioritized list, and the reason for each trade-off |
6. Self-assessment rubric
After each practice round, score yourself 0–3 on each line (0 = missing, 1 = partial, 2 = good, 3 = strong). Use the scores to choose a practice target. For example, repeat the same task after improving your explanation of input constraints.
| Area | What a 3 looks like |
|---|---|
| Understanding | Restated the problem, asked about inputs, edge cases, and constraints |
| Planning | Brute force first, then an improvement, with pseudocode |
| Correctness | Code works on the examples and edges without hints |
| Complexity | Stated time and space correctly and named the trade-off |
| Code quality | Clear names, small functions, early returns |
| Testing | Traced by hand, proposed specific tests |
| Communication | Thought aloud, calm tone, accepted hints, summarized at the end |
| Front-end quality | Semantic HTML, accessible, minimal state, clear component API |
Record what you missed and drill that one skill for a week (for example, binary search boundaries) rather than re-reading everything.
7. Readiness review of the whole pathway
Use this map to check yourself against the nine areas covered by this course. The official program has nine courses (source: https://www.coursera.org/professional-certificates/meta-front-end-developer (opens in a new tab)).
| # | Area | You should be able to… |
|---|---|---|
| 1 | Web foundations | Explain the request/response cycle, use developer tools, write semantic HTML, build a responsive page |
| 2 | JavaScript | Use functions, arrays, objects, modules, promises, and async/await; write Jest tests |
| 3 | Version control | Use the terminal, Git branches, remotes, pull requests, and resolve conflicts |
| 4 | HTML and CSS in depth | Build accessible forms, flexbox and grid layouts, states and animations |
| 5 | React basics | Write components with props and state, lists, conditional rendering, controlled forms, routing |
| 6 | Advanced React | Use effects with cleanup, context, reducers, refs, custom hooks, tests, and performance tools |
| 7 | UX and UI | Define users and journeys, wireframe, apply hierarchy and accessibility, run usability tests |
| 8 | Capstone | Plan, build, test, and present a complete booking application |
| 9 | Interviews | Solve problems with a method, choose structures and algorithms, and communicate clearly |
For each row, pick one concrete artifact from your own work as evidence: a repository link, a test, a design file, or a short write-up. A portfolio of three to five polished projects with clear READMEs, a clean Git history, and live demos usually communicates more than a long list of technologies.
A four-week plan after the course
- Week 1: redo problem A and two variants (different data, then a larger input). Write the complexity for each.
- Week 2: rebuild
SeatPicker, add tests for taken seats and the selection limit, and complete the flow with Tab, Enter, and Space. - Week 3: practice 10 binary search, sorting, and recursion exercises; one behavioral STAR story per week.
- Week 4: two complete timed mock interviews (with a partner if possible), then polish your portfolio and profile.
8. Interview practice tips
Practice aloud. Record a short solution explanation and listen for the assumptions, decisions, and test results you mention.
Close coding answers with the time and space bounds and one test that exercises an edge case.
Pitfalls:
- Memorizing solutions to published problems instead of the method.
- Jumping to the optimal solution without showing the reasoning.
- Ignoring accessibility in a UI problem.
- Over-engineering a simple component (extra state, extra libraries).
- Arguing with the interviewer instead of using hints.
- Claiming experience you do not have; say what you know and how you would learn the rest.
- Preparing only for code and not for behavioral questions.
- Treating practice scores as proof of the official credential; the certificate requires completing the official program.
9. Mini case study: debrief a failed mock interview
Situation. Priya runs a mock interview on Problem A. She starts typing after reading the prompt, builds nested loops, runs out of time with a half-working answer, and says nothing while stuck. Her partner reports: "You seemed to know the material, but I couldn't follow you."
Task. Write a debrief and an action plan using the rubric.
Solution, commented.
- Diagnosis with the rubric. Understanding 0 (no questions), Planning 0 (no brute-force-then-improve), Correctness 1, Complexity 0 (never stated), Communication 0 (silence). She knows
Set. Practising clarification and planning before typing can help her use it at the right point. - Highest-leverage fix. Enforce the first 8 minutes: restate, two examples, one edge case, pseudocode, and only then code. A visible timer or a checklist on paper makes this habit automatic.
- Communication drill. Practice a 60-second "plan out loud" for five different problems. Use the phrases from section 2.
- Redo. Solve Problem A again with the method; compare against the model walk-through.
- Measure. Rescore after two weeks. Compare Planning, Communication, and Correctness on the next attempt and record what changed.
Key terms
- STAR: Situation, Task, Action, Result structure for behavioral answers.
- Derived state: a value computed from existing state instead of stored.
- Rubric: a scoring guide used to assess an answer consistently.
- Mock interview: a practice interview run under realistic conditions.
- Portfolio: a curated set of projects that demonstrate your skills.
- Trade-off: a deliberate compromise between competing qualities.
Summary checklist
- I can run a timed practice interview with the five-step method.
- I think aloud, state complexity, and propose tests without being asked.
- I can build and explain a small accessible React component under time pressure.
- I can tell a STAR story about teamwork, conflict, and learning.
- I scored myself with the rubric and have a plan for the weakest area.
- I mapped each of the nine areas to evidence in my portfolio.
- I know where to check the official Meta program and credential requirements.
Sources
- Coding Interview Preparation (official ninth course): https://www.coursera.org/learn/coding-interview-preparation (opens in a new tab)
- Meta Front-End Developer Professional Certificate (official program page): https://www.coursera.org/professional-certificates/meta-front-end-developer (opens in a new tab)
- React documentation, Thinking in React: https://react.dev/learn/thinking-in-react (opens in a new tab)
- React render and commit (opens in a new tab)
- React state updates (opens in a new tab)
- WAI-ARIA button pattern (opens in a new tab)
- Testing Library user-event (opens in a new tab)
