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: Checks that you understand scope and hoisting, which explain many real bugs in JavaScript code.
Answer
var is function-scoped, is hoisted and initialised to undefined, and can be re-declared.let is block-scoped ({ ... }), is hoisted but sits in the temporal dead zone until its declaration runs, and cannot be re-declared in the same scope.const behaves like let but the binding cannot be reassigned. The value itself is not frozen: you can still change an object's properties or push to an array.for (var i = 0; i < 3; i++) setTimeout(() => console.log(i)); // 3 3 3
for (
Why they ask this: Checks that you understand what React does for you rather than only using its syntax.
Answer
The virtual DOM is a lightweight JavaScript description of the UI (React elements). When state or props change:
Diffing rules worth knowing:
<div> vs <span>, or different components) are replaced entirely.key tells React which item is which, so it can reuse and move elements correctly.Touching the real DOM is the slow part, so batching updates and changing only what differs keeps the UI fast and lets you write declarative code.
Why they ask this: Loose equality causes subtle bugs; interviewers want to see that you default to strict comparison.
Answer
Why they ask this: A classic fundamentals check that also reveals whether you understand let/const and the temporal dead zone.
Answer
Why they ask this: A quick fundamentals question that checks attention to detail.
Answer
Why they ask this: Hooks are how modern React is written; breaking the rules causes hard-to-find bugs.
Answer
Why they ask this: Wrong keys cause subtle UI bugs, so this checks practical experience.
Answer
Why they ask this: The most basic React concept; a weak answer is a red flag for any React role.
Answer
Why they ask this: Shows you care about accessibility and SEO, not only how a page looks.
Answer
Why they ask this: Layout bugs often come from misunderstanding widths, padding and borders.
Answer
Why they ask this: Checks you can choose the right layout tool instead of fighting CSS.
Answer
Why they ask this: Positioning is needed for dropdowns, modals and sticky headers.
Answer
Rule of thumb: use const by default, let when you must reassign, and avoid var in modern code.
=== (strict equality) compares value and type. No conversion happens.== (loose equality) converts the operands to a common type first, then compares.0 == '0' // true (string converted to number)
0 === '0' // false (number vs string)
null == undefined // true
null === undefined// false
'' == 0 // trueAlways use === (and !==) unless you deliberately want conversion. A common, accepted exception is value == null, which checks for both null and undefined.
Hoisting means declarations are processed before code runs, so they are known in their whole scope.
var is hoisted and initialised to undefined.let, const and class are hoisted too, but stay uninitialised (the temporal dead zone) until the declaration line runs. Accessing them earlier throws a ReferenceError.greet(); // works
function greet() { console.log('Namaste'); }
console.log(a); // undefined
var a = 1;
console.log(b); // ReferenceError
let b = 2;Function expressions (const greet = () => {}) follow the rules of the variable they are assigned to.
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'.
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.
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} />
))}| 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.
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>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.
/* Flexbox: navbar */
.nav { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
/* Grid: responsive cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }They work well together, for example a Grid page layout with Flexbox inside each card.
static (default): normal document flow. top/left have no effect.relative: stays in the flow, but can be nudged with top/left. It also becomes the containing block for absolutely positioned children.absolute: removed from the flow and positioned relative to the nearest positioned ancestor (any value other than static), or the initial containing block if there is none.fixed: removed from the flow and positioned relative to the viewport, so it stays put while scrolling. Note that a transform on an ancestor changes this.sticky: acts like relative until a scroll threshold (such as top: 0) is reached, then sticks within its parent..dropdown-wrapper { position: relative; }
.dropdown-menu { position: absolute; top: 100%; left: 0; }
.site-header { position: sticky; top: 0; }