Frontend Developer interview questions
100 real questions with model answers and explanations for Junior candidates.
See a Frontend Developer resume example →Questions
These three display types differ in flow and box behavior.
- Block: takes full parent width, starts on a new line (div, p, h1).
- Inline: takes only content width, flows in line, ignores width/height (span, a, strong).
- Inline-block: flows inline but accepts width, height, padding, margin like a block.
Why interviewers ask this: This tests whether the candidate understands the fundamental display model and can predict how elements will lay out on a page.
Specificity is a score that decides which CSS rule wins for the same element and property.
- Calculated across four categories: inline styles, IDs, classes and pseudo-classes, element selectors.
- Each category outweighs the ones below it, so a higher score always wins regardless of source order.
- !important overrides everything but should be used sparingly.
Why interviewers ask this: This tests whether the candidate can debug conflicting styles systematically without resorting to !important abuse.
Every element is a rectangular box made of four layers.
- Content: the text or image area.
- Padding: transparent space between content and border.
- Border: wraps the padding.
- Margin: outer space separating the element from neighbors.
- box-sizing: border-box makes width and height include padding and border, the modern default.
Why interviewers ask this: This reveals how well the candidate understands element sizing and spacing, which is fundamental to layout work.
The difference is whether the element stays in the document flow.
- position: relative keeps the element in flow but lets you offset it with top, right, bottom, left without displacing neighbors.
- position: absolute removes it from flow and positions it against the nearest ancestor with a position other than static.
- With no such ancestor, it positions against the initial containing block.
Why interviewers ask this: Misunderstanding positioning is one of the most common layout bugs for beginners, so this tests practical foundational knowledge.
Flexbox is a one-dimensional layout system enabled by display: flex on a container.
- Main axis: the primary direction items flow, set by flex-direction, horizontal by default.
- Cross axis: runs perpendicular to the main axis.
- justify-content aligns items along the main axis; align-items aligns them along the cross axis.
Why interviewers ask this: This checks whether the candidate understands Flexbox conceptually and can use it without trial and error.
CSS Grid is a two-dimensional layout system for rows and columns.
- You define explicit rows and columns on a container and place items in that grid.
- Flexbox fits one-dimensional layouts where items flow in one direction, like a nav bar or a row of cards.
- Grid wins when you control both dimensions at once, like a page with header, sidebar, main, and footer.
Why interviewers ask this: The interviewer wants to see that the candidate can choose the right layout tool for the situation rather than defaulting to one approach for everything.
These units differ in what they are relative to.
- px: absolute, does not scale with user or browser settings.
- em: relative to the parent font size, can compound when nested.
- rem: relative to the root html font size, more predictable for global scaling.
- vw and vh: viewport units equal to 1 percent of viewport width or height, useful for full-screen sections.
Why interviewers ask this: This tests whether the candidate understands responsive and accessible sizing, which matters for UIs that respect user font preferences.
Build mobile-first and progressively enhance for wider screens.
- Start from a mobile base layout, then add min-width media queries for larger screens.
- Use flexible units like percentages and rem for widths and font sizes.
- Use Flexbox or Grid for layout containers.
- Avoid fixed widths and set max-width on page containers so content does not overflow.
Why interviewers ask this: This evaluates whether the candidate has a real strategy for responsive design or only knows the concept in theory.
Semantic HTML uses elements that convey the meaning of their content.
- Use header, nav, main, article, section, footer instead of generic divs everywhere.
- Browsers, search engines, and assistive tech read these signals to understand document structure.
- This improves screen reader accessibility, boosts SEO, and makes code easier to read.
Why interviewers ask this: This checks whether the candidate thinks beyond visual output and considers the structural and accessibility implications of markup choices.
Media queries apply CSS only when a condition is met, usually a viewport width.
- A query like @media (min-width: 768px) activates styles only on screens at least 768px wide.
- Combine conditions with and, or target print versus screen with the media type.
Why interviewers ask this: This directly tests knowledge of the primary tool for responsive design.
z-index controls the stacking order of positioned elements, higher in front.
- It only works on elements with a position other than static, or on flex and grid children.
- A stacking context is a self-contained layer where z-index values are compared only within that group.
- So a child with a huge z-index cannot rise above an ancestor that forms a lower stacking context.
Why interviewers ask this: Stacking context confusion is a common source of z-index bugs and tests whether the candidate understands why expected layering sometimes does not work.
All three hide an element but differ in space, events, and accessibility.
- display: none removes the element from flow, takes no space, and is invisible to screen readers.
- visibility: hidden hides it visually but keeps its space in the layout.
- opacity: 0 makes it transparent but it still takes space, receives clicks, and stays accessible.
Why interviewers ask this: This tests attention to the subtle behavioral differences that matter for animations, accessibility, and layout stability.
The alt attribute gives a text description of an image.
- It shows when the image fails to load and is read aloud by screen readers for visually impaired users.
- A descriptive alt improves accessibility and image SEO.
- For purely decorative images, set alt to an empty string so screen readers skip it.
Why interviewers ask this: This checks whether the candidate understands basic image accessibility, which is a WCAG requirement.
The cascade decides which rule applies when several target the same element and property.
- It evaluates origin and importance first.
- Then specificity of the selectors.
- Then source order, so when specificity is equal the later rule wins.
Why interviewers ask this: This tests foundational CSS reasoning and whether the candidate can diagnose style conflicts systematically.
Padding is space inside the element, margin is space outside it.
- Padding sits between content and border and takes on the element background color.
- Margin is transparent space between the border and neighboring elements.
- Adjacent vertical margins between blocks collapse to the larger value, which padding never does.
Why interviewers ask this: Margin collapsing is a specific behavior that trips up beginners, so this tests whether the candidate understands the practical difference between the two spacing mechanisms.
They differ in scope, hoisting, and reassignment.
- var is function-scoped and hoisted, so it can be read before its declaration, causing subtle bugs.
- let and const are block-scoped, living only inside the nearest curly braces.
- const blocks reassignment of the binding but does not make objects or arrays immutable.
Why interviewers ask this: This tests knowledge of scoping and hoisting, which are foundational to writing predictable JavaScript.
Bubbling is how an event travels up the DOM after firing.
- It first triggers handlers on the target element, then on each ancestor up to document.
- Clicking a button inside a div also fires click handlers on the div and its ancestors.
- You stop it by calling event.stopPropagation() inside a handler.
Why interviewers ask this: Understanding bubbling is essential for event delegation and for avoiding unexpected handler triggers.
A closure is a function that keeps access to its outer scope variables after that scope returns.
- This works because functions carry a reference to the environment where they were defined.
- A classic example is a counter factory where each call gets its own private count variable.
Why interviewers ask this: Closures are a core JavaScript concept and this tests whether the candidate understands lexical scoping at a deeper level.
=== checks value and type, == coerces types before comparing.
- === returns true only when both value and type match exactly.
- == coerces types first, so 0 and false or null and undefined can be equal.
- Prefer === almost everywhere to avoid hard-to-trace coercion surprises.
Why interviewers ask this: This tests awareness of type coercion, which is a frequent source of bugs for beginners.
The value of this depends on how a function is called, not where it is defined.
- In a method call, this is the object before the dot.
- In a standalone call in strict mode, this is undefined.
- Arrow functions have no own this and inherit it from the surrounding lexical scope.
Why interviewers ask this: this is one of the most misunderstood aspects of JavaScript and this question separates candidates who truly understand function context from those who only memorize rules.
Locked questions
- 21
What is a Promise in JavaScript and why is it useful?
promisesjavascript - 22
What is async/await and how does it relate to Promises?
asyncpromises - 23
What is the difference between null and undefined in JavaScript?
fundamentalsjavascript - 24
What is the JavaScript event loop and why does it matter?
event-loopjavascript - 25
What is the difference between map, filter, and reduce on arrays?
arrays - 26
How do arrow functions differ from regular function expressions?
functions - 27
What is destructuring in JavaScript and give a practical example.
destructuringjavascript - 28
What are the spread and rest operators and how do they differ?
restspread - 29
What is the DOM and how do you select and update elements with JavaScript?
domjavascript - 30
What is event delegation and why is it a useful pattern?
dom - 31
What is the difference between localStorage and sessionStorage?
sessions - 32
What is JSON and how do you parse and serialize it in JavaScript?
serializationjavascript - 33
How do you make a data fetch request in JavaScript using the fetch API?
javascript - 34
How does prototypal inheritance work in JavaScript?
prototypesjavascript - 35
What is the difference between call, apply, and bind?
functions - 36
What is React and what core problem does it solve?
react - 37
What is the difference between a React element and a React component?
reactcomponents - 38
What are props in React and how do you pass them to a child component?
reactcomponents - 39
What is state in React and how does it differ from props?
react - 40
How does the useState hook work?
hooks - 41
How does the useEffect hook work and what controls when it runs?
hooks - 42
What is the virtual DOM and how does React use it?
reactdomvirtual-dom - 43
What is a common mistake when attaching event handlers in React JSX?
ownershipreact - 44
How do you render a list of items in React and why do keys matter?
react - 45
What is conditional rendering in React and what are common patterns?
react - 46
What does lifting state up mean in React?
react - 47
What is the React Context API and when is it a good fit?
reactstateapi - 48
What is a custom hook in React and why are they useful?
reacthooks - 49
What is the difference between a controlled and an uncontrolled input in React?
reactforms - 50
What is prop drilling and how can you avoid it?
state - 51
What is TypeScript and why do many teams prefer it over plain JavaScript?
typescriptjavascript - 52
What is the difference between an interface and a type alias in TypeScript?
typescripttypes - 53
What is a union type in TypeScript and how do you narrow it?
typescripttypes - 54
How do you add TypeScript types to a React component's props?
reactcomponentstypescript - 55
What are generics in TypeScript and can you give a simple example?
typescriptgenerics - 56
What is the purpose of a package manager like npm or pnpm and what does package.json do?
pnpmnpm - 57
What does a JavaScript bundler like Vite or Webpack do?
webpackvitebundling - 58
What is Git and what is the difference between git merge and git rebase?
git - 59
How do you debug a JavaScript runtime error in the browser?
javascript - 60
What is ESLint and what value does it provide on a development team?
eslint - 61
What is Prettier and how does it differ from a linter?
prettierlinting - 62
What is CORS and why do you encounter it in frontend development?
cors - 63
What is hot module replacement and why is it valuable?
hmr - 64
What is the difference between a development build and a production build?
build - 65
What is tree-shaking and how does it affect bundle size?
bundle-size - 66
What types of tests are used in frontend development and how do they differ?
testing - 67
What is React Testing Library and what philosophy guides it?
rtlreact - 68
What is mocking in tests and why is it needed?
mocking - 69
What are Core Web Vitals and why should frontend developers care about them?
web-vitals - 70
What is lazy loading and how do you apply it to images?
lazy-loading - 71
What does web accessibility mean and why is it a developer responsibility?
a11y - 72
How do screen readers interpret web pages and what can you do to support them?
a11y - 73
How do you investigate a React component that re-renders too frequently?
reactcomponents - 74
Your API call works locally but fails in production. What do you check first?
api - 75
What are the main ways to center an element both horizontally and vertically with CSS?
cssscaling - 76
A user reports that the layout breaks on their phone. How do you approach fixing it?
- 77
How do you show a loading indicator while waiting for API data in React?
reactapi - 78
What is a React Fragment and when should you use one?
react - 79
What is code splitting and how does it improve frontend performance?
performance - 80
What is an environment variable and why do you use them in frontend projects?
config - 81
What is Tailwind CSS and how does its approach differ from writing traditional CSS?
csstailwind - 82
Why should you not routinely suppress linter warnings with disable comments?
linting - 83
How do you approach understanding an unfamiliar codebase on your first day?
learning - 84
How do you handle critical feedback on your code during a code review?
soft-skillsfeedbackcode-review - 85
How do you approach learning a new JavaScript library or framework?
javascript - 86
How do you decide when to ask for help versus spending more time solving a problem yourself?
- 87
What makes a good Git commit message?
git - 88
Tell me about a project you are proud of. What did you build and what did you learn?
story - 89
How do you report a blocker to your team when you are stuck on something?
problem-solvingcommunication - 90
What is a pull request and what should a good description include?
code-review - 91
What is the purpose of a .gitignore file?
git - 92
What is the difference between a GET and a POST HTTP request?
http - 93
What does an HTTP 404 status code mean and how do you handle it in a frontend app?
httpstatus-codessoft-skills - 94
What is the useRef hook in React and what are its two main use cases?
reacthooks - 95
What is a loading skeleton and when should you use it instead of a spinner?
ux - 96
What is Storybook and how does it help frontend teams?
storybook - 97
What makes a form field accessible?
forms - 98
What is the Lighthouse tool and how do you use it?
web-vitals - 99
How would you implement dark mode support in a React application?
reacttheming - 100
Where do you want to be as a frontend developer in two years and what are you doing to get there?
growth