Practice 60 original frontend interview questions covering JavaScript, HTML, CSS, React, the browser, performance, accessibility, and security, with answers and explanations.
Level: Frontend InterviewDifficulty: intermediate60 questions60 min
Choose a practice mode, answer each frontend interview question, then review the explanation. Wrong answers are saved locally for review.
Day streak: 0 daysSaved only on this device
Progress0 / 60
Time left: 00:00
No wrong answers saved yet.
No questions match your filters.
Question 1
What is a JavaScript closure?
A closure is created when a function keeps access to variables from its outer scope even after the outer function returns. It enables data privacy and functional patterns.
Question 2
What is hoisting in JavaScript?
Hoisting moves variable and function declarations to the top of their scope before execution. `let` and `const` are hoisted but not initialized, so they are not accessible before their declaration.
Question 3
What is the difference between == and ===?
The loose equality operator == converts operands to a common type, while === requires the same type and value. Strict equality avoids surprising coercions.
Question 4
What is a Promise?
A Promise represents a value that may be available now, later, or never, and supports .then, .catch, and .finally. It is not a loop, event, or animation.
Question 5
What does async/await do?
async/await is syntactic sugar over Promises that lets developers write asynchronous code more readably. It does not create workers, block the loop by design, or convert CSS.
Question 6
What is event delegation?
Event delegation uses bubbling to handle events from many children with one parent listener. It improves performance and works for dynamically added elements.
Question 7
What does `this` refer to in JavaScript?
The value of `this` depends on how a function is called: method call, function call, arrow function, or explicit binding. It is not always global or a DOM element.
Question 8
What is a pure function?
A pure function always returns the same result for the same arguments and does not modify external state. It is easier to test and reason about.
Question 9
What is immutability?
Immutable data is not modified after creation; updates create new values instead. This reduces bugs and helps predictable UI updates.
Question 10
Which array method creates a new array by transforming each element?
.map() returns a new array with each element transformed. .filter() keeps matching elements, .reduce() accumulates a value, and .find() returns the first match.
Question 11
Which array method returns elements that match a condition?
.filter() returns a new array with elements that pass a condition. .map() transforms, .push() adds an item, and .sort() orders elements.
Question 12
Which array method reduces an array to a single value?
.reduce() applies a reducer function to accumulate a single result. .join() creates a string, .slice() copies a portion, and .concat() combines arrays.
Question 13
What is a Set in JavaScript?
A Set stores unique values and ignores duplicates. It is not sorted by default, not a key-value object, and not a tree.
Question 14
What is localStorage?
localStorage stores key-value data in the browser and persists across sessions. It is not server-side, a CSS property, or a React hook.
Question 15
What is semantic HTML?
Semantic HTML uses meaningful elements that describe structure and content, improving accessibility and SEO. Divs and spans are generic and should be used when no semantic element fits.
Question 16
Which landmark element represents the main content of a page?
<main> is a landmark for the primary content of a page. <section> groups related content, and div and span are generic containers.
Question 17
What is CSS specificity?
Specificity determines which CSS rule applies when selectors conflict. IDs have higher specificity than classes, and classes have higher specificity than elements.
Question 18
In the CSS box model, which property sits between padding and margin?
The box model order is content, padding, border, and margin. The border sits between padding and margin; outline is drawn outside the border.
Question 19
What is flexbox designed for?
Flexbox handles one-dimensional layout along a main axis, while CSS Grid handles two-dimensional row and column layout. It is not for print or databases.
Question 20
What is CSS Grid designed for?
CSS Grid creates two-dimensional layouts by defining rows and columns together. Flexbox is better for one-dimensional layouts, and grid is not for text or timing.
Question 21
Which CSS unit is relative to the root font size?
rem is relative to the root html font size, while em is relative to the parent font size. px is absolute and vh is relative to viewport height.
Question 22
Which CSS unit is relative to viewport width?
vw equals 1% of viewport width, and vh equals 1% of viewport height. rem is root-relative and ch is character width.
Question 23
What does a media query do?
Media queries apply CSS conditionally, usually based on screen size, orientation, or capabilities. They do not connect databases, load fonts, or handle events.
Question 24
What does position: fixed do?
position: fixed places an element relative to the viewport so it stays in place while scrolling. Absolute positions relative to an ancestor, and static/relative follow normal flow.
Question 25
What is a pseudo-class?
Pseudo-classes select states or positions, such as :hover, :focus, and :first-child. They are not generated classes, variables, or attributes.
Question 26
What does box-sizing: border-box do?
box-sizing: border-box makes width and height include content, padding, and border, which simplifies sizing. It does not remove borders, center, or create grids.
Question 27
What is a React component?
A React component is a reusable function or class that renders UI. It is not a CSS class, event, or database table.
Question 28
What are props in React?
Props are read-only inputs passed from parent to child components. State is managed inside a component, and props are not DOM nodes or globals.
Question 29
What is state in React?
State is component-owned data that can change and trigger re-renders. Props are passed in from parents; state is not a cache or stylesheet.
Question 30
What is a React hook?
Hooks such as useState and useEffect let function components use React features. They are not animations, APIs, or selectors.
Question 31
Which hook manages state in a function component?
useState returns a state value and its setter. useEffect runs side effects, useRef holds mutable references, and useReducer manages complex state with reducers.
Question 32
Which hook runs side effects after render?
useEffect runs side effects such as data fetching or subscriptions after render. useState manages values, useMemo memoizes computations, and useContext reads context.
Question 33
What is the virtual DOM?
React keeps a virtual DOM in memory, diffs changes, and updates the real DOM efficiently. It is not the real DOM, a template, or a CSS layer.
Question 34
Why do list items need keys in React?
Keys give list items stable identities so React can reconcile changes efficiently. They are not for styling, events, or storage.
Question 35
What is a controlled input in React?
A controlled input derives its value from state and updates state on change. Uncontrolled inputs manage their own value in the DOM.
Question 36
What is reconciliation in React?
Reconciliation is how React compares the previous and next virtual DOM and applies minimal real DOM updates. It is not database merging, CSS compiling, or bundling.
Question 37
What does useMemo do?
useMemo caches the result of a computation until dependencies change. useRef creates mutable refs, useEffect runs effects, and useState manages state.
Question 38
What is the DOM?
The Document Object Model represents HTML as a tree of nodes that scripts can read and modify. It is not a database, preprocessor, or protocol.
Question 39
Which method selects an element by its id?
document.getElementById() returns the element with a matching id. querySelectorAll returns multiple matches, createElement creates nodes, and fetch makes network requests.
Question 40
Which method attaches an event listener?
addEventListener() registers a handler for an event. setTimeout delays code, appendChild adds nodes, and getAttribute reads attributes.
Question 41
What is event bubbling?
Bubbling means an event on a target also triggers handlers on its ancestors. The capture phase travels from the root down to the target.
Question 42
What is the event loop?
The event loop manages the call stack, task queue, and microtask queue so asynchronous callbacks run at the right time. It is not DOM, CSS, or network logic.
Question 43
What is a microtask?
Microtasks, including promise callbacks, run after the current task and before the next task. They are not workers, long functions, or cookies.
Question 44
What is requestAnimationFrame used for?
requestAnimationFrame schedules a callback before the next repaint for smooth animations. It is not for network requests, debouncing, or measuring.
Question 45
What is a cookie?
Cookies are small pieces of data that browsers store and send to servers with requests, often for sessions and tracking. They are not variables, units, or hooks.
Question 46
What does stopPropagation do?
stopPropagation prevents the event from continuing to bubble or capture. preventDefault stops the default action such as form submission or navigation.
Question 47
What is debouncing?
Debouncing waits for a quiet period before calling a function, useful for search inputs. Throttling limits calls to once per interval, which is different.
Question 48
What is throttling?
Throttling ensures a function runs at most once per interval, useful for scroll or resize handlers. Debouncing waits for a pause instead.
Question 49
What is lazy loading?
Lazy loading defers images, scripts, or routes until needed, reducing initial load. It is not about network speed or API caching.
Question 50
What are Core Web Vitals?
Core Web Vitals measure loading, interactivity, and visual stability with metrics such as LCP, INP, and CLS. They are not database, network, or ad metrics.
Question 51
Which Core Web Vital measures visual stability?
Cumulative Layout Shift (CLS) measures unexpected layout shifts. LCP measures loading, INP measures interactivity, and TTFB measures server response.
Question 52
Which Core Web Vital measures loading performance?
Largest Contentful Paint (LCP) measures when the main content becomes visible. CLS measures layout stability, and INP/FID measure interactivity.
Question 53
What is ARIA?
ARIA attributes communicate roles, states, and properties to assistive technology. They are not a framework, library, or extension.
Question 54
What is XSS?
Cross-site scripting injects malicious scripts into trusted pages, often through unescaped user input. It is not CSS, caching, or a React error.
Question 55
What is a Content Security Policy?
CSP is a security header that restricts scripts, styles, and other resources to reduce XSS risk. It is not a cookie, database, or CSS rule.
Question 56
What is CORS?
CORS lets servers declare which origins may access their resources through browser headers. It is not CSS, a framework, or a DOM method.
Question 57
Which of the following are JavaScript array methods? Select all that apply.
.map(), .filter(), and .reduce() are JavaScript array methods. .append() is a DOM method, not an array method.
Question 58
Which of the following are React hooks? Select all that apply.
useState, useEffect, and useMemo are React hooks. useDOM is not a built-in React hook.
Question 59
Flexbox is the best choice for two-dimensional grid layouts.
Flexbox is best for one-dimensional layouts. CSS Grid is designed for two-dimensional row and column layouts, so the statement is false.
Question 60
Match each CSS unit to its meaning.
rem is root-relative, vw is viewport width, vh is viewport height, and percent is relative to the parent.