Filter by the role you are applying for, open a question, and practise explaining the answer out loud. Mark it practised when you can.
Why they ask this: Almost every app calls APIs; interviewers check you can write and handle async code correctly.
Answer
A Promise represents a value that will be available later (pending, then fulfilled or rejected). async/await is syntax on top of promises that makes async code read like synchronous code.
// Promise chain
fetch('/api/jobs')
.then((res) => res.json())
.then((jobs) => console.log(jobs))
.catch((err) => console.error(err));
// async/await
async function loadJobs() {
try {
const res = await fetch('/api/jobs');
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return await res.json();
} catch (err) {
console.error(err);
}
}Points worth mentioning:
async function always returns a promise.try/catch for errors with await.await Promise.all([...]) instead of awaiting one after another.Why they ask this: A quick fundamentals question that checks attention to detail.
Answer
undefined means a value was never assigned: an uninitialised variable, a missing object property, a missing function argument, or a function with no return.null is an intentional "no value" that a developer assigns.let a; // undefined
const obj = {};
obj.missing; // undefined
let b = null; // explicitly empty
typeof undefined; // 'undefined'
typeof null; // 'object' (a historical bug)
null == undefined; // true
null === undefined; // falseUse ?? (nullish coalescing) to give a default for both: const name = input ?? 'Guest'.
Why they ask this: Tests your understanding of DOM event bubbling and performance with dynamic lists.
Answer
Most DOM events bubble up from the target element to its ancestors. Event delegation puts one listener on a parent and uses event.target to work out which child was clicked.
document.querySelector('#todo-list').addEventListener('click', (event) => {
const button = event.target.closest('button.delete');
if (!button) return;
button.closest('li').remove();
});Benefits:
Use event.stopPropagation() carefully, because it breaks delegation for listeners higher up.
Why they ask this: Common in search boxes, scroll and resize handlers; shows you think about performance.
Answer
Both limit how often a function runs:
function debounce(fn, delay = 300) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), delay);
};
}
const onSearch = debounce((q) => fetch(`/api/search?q=${encodeURIComponent(q)}`));Why they ask this: Hooks are how modern React is written; breaking the rules causes hard-to-find bugs.
Answer
Hooks are functions that let function components use React features: useState (state), useEffect (side effects), useContext, useRef, useMemo, useCallback, and your own custom hooks (useSomething).
Rules of hooks:
function Profile({ userId }) {
const [user, setUser] = useState(null); // top level: OK
// if (userId) { useEffect(...) } // wrong: conditional hook
useEffect(() => {
if (!userId) return; // put the condition inside
fetch(`/api/users/${userId}`).then((r) => r.json()).then(setUser);
}, [userId]);
return <p>{user?.name}</p>;
}The eslint-plugin-react-hooks lint rules catch most mistakes.
Why they ask this: Most React bugs (infinite loops, stale data, memory leaks) come from misusing useEffect.
Answer
useEffect(effect, deps) runs effect after render:
[]: runs once after the first render (mount).[a, b]: runs after the first render and again whenever a or b changes (compared with Object.is).The function you return is the cleanup. It runs before the effect runs again and when the component unmounts. Use it to remove listeners, clear timers and cancel requests.
useEffect(() => {
const controller = new AbortController();
fetch(`/api/jobs?q=${query}`, { signal: controller.signal })
.then((r) => r.json())
.then(setJobs)
.catch(() => {});
return () => controller.abort(); // cancel the old request when query changes
}, [query]);Include every value from the component that the effect uses in the array. Missing dependencies cause stale values.
Why they ask this: Wrong keys cause subtle UI bugs, so this checks practical experience.
Answer
A key gives each list item a stable identity, so React can tell which items were added, removed or reordered between renders and keep the right state and DOM node for each one.
{todos.map((todo) => (
<TodoItem key={todo.id} todo={todo} />
))}Why they ask this: Forms are in every app; this shows how you handle user input and validation.
Answer
value comes from state and every change goes through onChange.ref or from the form data on submit.// Controlled
const [email, setEmail] = useState('');
<input value={email} onChange={(e) => setEmail(e.target.value)} />
// Uncontrolled
const inputRef = useRef(null);
<input ref={inputRef} defaultValue="" />
// later: inputRef.current.valueChoose controlled inputs for instant validation, formatting or conditional UI. Uncontrolled inputs are simpler for basic forms and file inputs (<input type="file"> is always uncontrolled). Form libraries such as React Hook Form mostly use uncontrolled inputs for performance.
Why they ask this: The most basic React concept; a weak answer is a red flag for any React role.
Answer
| Props | State | |
|---|---|---|
| Owned by | the parent | the component itself |
| Changeable by the component? | No, read-only | Yes, through the setter (setX) |
| Purpose | configure a component and pass data down | data that changes over time |
function Counter({ step }) { // step is a prop
const [count, setCount] = useState(0); // count is state
return <button onClick={() => setCount((c) => c + step)}>{count}</button>;
}Changing either one re-renders the component. When two siblings need the same data, lift the state up to their common parent and pass it down as props.
Why they ask this: Separates candidates who understand rendering performance from those who memoise everything by habit.
Answer
useMemo(fn, deps) caches a computed value until deps change.useCallback(fn, deps) caches a function reference until deps change. It is the same as useMemo(() => fn, deps).Use them when:
React.memo, and a new reference every render would defeat it.useEffect) and a new reference would re-run it every render.const visibleJobs = useMemo(
() => jobs.filter((j) => j.title.toLowerCase().includes(query.toLowerCase())),
[jobs, query],
);
const handleSelect = useCallback((id) => setSelected(id), []);Skip them for cheap calculations and for handlers passed to plain DOM elements. Memoisation itself costs memory and comparisons, so measure with the React DevTools Profiler before you optimise. (React Compiler can add this memoisation automatically in projects that use it.)
Why they ask this: Shows you care about accessibility and SEO, not only how a page looks.
Answer
Semantic HTML uses elements that describe their meaning, not only their appearance: <header>, <nav>, <main>, <article>, <section>, <aside>, <footer>, <button>, <label>, and headings <h1>–<h6> in order.
Why it matters:
<button> is keyboard-focusable and clickable with Enter or Space by default; a clickable <div> is not.<main>
<article>
<h1>Frontend Developer at Kathmandu Tech</h1>
<p>...</p>
<button type="button">Apply now</button>
</article>
</main>Why they ask this: Layout bugs often come from misunderstanding widths, padding and borders.
Answer
Every element is a box made of four layers, from inside out: content → padding → border → margin.
box-sizing: content-box, width sets only the content. Padding and border are added on top, so width: 200px; padding: 20px; border: 1px renders 242px wide.box-sizing: border-box, width includes padding and border, so the element stays 200px wide. This is far easier to reason about.*, *::before, *::after {
box-sizing: border-box;
}Margins are outside the box and can collapse: vertical margins of adjacent block elements combine into the larger of the two instead of adding up.