Front-end Development Interview Questions - Answers
1. HTML Concepts
What is the difference between <div> and <span> elements?
<div>is a block-level element that starts on a new line and takes up full width available<span>is an inline element that flows with surrounding content and only takes up necessary width- Use
<div>for structural sections,<span>for styling small portions of text
Explain the purpose of semantic HTML tags and their importance.
Semantic tags (<header>, <nav>, <article>, <section>, <footer>) describe their content's meaning, not just appearance. Benefits include:
- Improved accessibility for screen readers
- Better SEO as search engines understand content structure
- Easier code maintenance and readability
How do you make a web page accessible for users with disabilities?
- Use semantic HTML and proper heading hierarchy
- Add alt text to images
- Ensure keyboard navigation works (tab order, focus states)
- Provide sufficient color contrast (WCAG standards)
- Use ARIA labels when semantic HTML isn't enough
- Make forms accessible with proper labels
2. CSS Fundamentals
What is the box model in CSS, and how does it work?
Every element is a box with four layers (inside to outside):
- Content: actual content (text, images)
- Padding: space between content and border
- Border: surrounds padding
- Margin: space outside border separating from other elements
box-sizing: border-box includes padding and border in the element's width/height.
Explain the difference between inline, block, and inline-block elements.
- Block: Starts new line, takes full width (
<div>,<p>,<h1>) - Inline: Flows with text, ignores width/height (
<span>,<a>) - Inline-block: Flows inline but respects width/height settings
How do you center an element horizontally and vertically using CSS?
Modern approaches:
/* Flexbox */
.container {
display: flex;
justify-content: center;
align-items: center;
}
/* Grid */
.container {
display: grid;
place-items: center;
}
3. JavaScript Essentials
What is the difference between let, const, and var in JavaScript?
var: Function-scoped, hoisted, can be redeclared (legacy, avoid)let: Block-scoped, can be reassigned, not redeclaredconst: Block-scoped, cannot be reassigned (but objects/arrays are mutable)
Explain the concept of closures in JavaScript.
A closure is when a function retains access to variables from its outer scope even after the outer function has finished executing. Common uses include data privacy and creating factory functions.
Example:
function createCounter() {
let count = 0;
return function () {
count++;
return count;
};
}
const counter = createCounter();
console.log(counter()); // 1
console.log(counter()); // 2
How do you implement event delegation in JavaScript?
Attach a single event listener to a parent element instead of multiple listeners to children. Use event.target to identify which child triggered the event.
Example:
document.querySelector('#parent').addEventListener('click', (e) => {
if (e.target.matches('.child-button')) {
console.log('Button clicked:', e.target);
}
});
Benefits:
- Better performance
- Handles dynamically added elements
4. Front-end Frameworks/Libraries
What are the advantages of using a front-end framework like React or Angular?
- Component-based architecture for reusability
- Efficient DOM updates through virtual DOM or change detection
- Strong ecosystem and tooling
- Easier state management
- Built-in routing and development patterns
How does React's virtual DOM work, and why is it important?
React maintains a lightweight copy of the DOM in memory. When state changes:
- Creates new virtual DOM tree
- Compares (diffs) with previous version
- Calculates minimal changes needed
- Updates only changed parts of real DOM
This is faster than manipulating the DOM directly for complex UIs.
Explain the concept of state management in front-end frameworks.
State management handles application data flow. Local state lives in components, while global state (Redux, Zustand, Context API) is shared across the app. It ensures UI reflects data changes consistently and predictably.
5. Web Performance Optimization
What are some techniques you can use to optimize website performance?
- Minimize and compress assets (CSS, JS, images)
- Lazy load images and components
- Use CDNs for static assets
- Reduce HTTP requests
- Implement code splitting
- Optimize images (WebP format, responsive images)
- Enable compression (Gzip/Brotli)
- Minimize render-blocking resources
How does browser caching work, and how can you leverage it?
Browsers store resources locally to avoid re-downloading. Control with HTTP headers:
Cache-Control: Sets caching durationETag: Validates if cached version is still fresh- Use content hashing in filenames for cache busting
Example:
Cache-Control: public, max-age=31536000, immutable
Explain the concept of code splitting and its importance in web applications.
Code splitting breaks your bundle into smaller chunks loaded on-demand. Benefits:
- Faster initial page load (only load what's needed)
- Better caching (unchanged chunks stay cached)
- Improved performance on slower connections
Example in React:
const Dashboard = React.lazy(() => import('./Dashboard'));
6. Responsive Web Design
What is the difference between responsive and adaptive web design?
- Responsive: Fluid layouts that adjust smoothly to any screen size using flexible grids and media queries
- Adaptive: Fixed layouts for specific breakpoints, serving different designs for predetermined screen sizes
How do you implement media queries in CSS for responsive design?
/* Mobile first approach */
.element {
width: 100%;
}
@media (min-width: 768px) {
.element {
width: 50%;
}
}
@media (min-width: 1024px) {
.element {
width: 33.33%;
}
}
Explain the concept of mobile-first design and its advantages.
Design for mobile screens first, then enhance for larger screens.
Advantages:
- Forces prioritization of essential content
- Better performance on mobile (progressive enhancement)
- Easier to scale up than down
- Aligns with mobile-first indexing by search engines
7. Version Control with Git
What is the difference between git pull and git fetch?
git fetch: Downloads changes from remote but doesn't merge themgit pull: Downloads changes AND merges them (fetch+merge)
Use fetch to review changes before merging.
How do you resolve merge conflicts in Git?
- Git marks conflicts in files with
<<<<<<<,=======,>>>>>>> - Open conflicted files and choose which changes to keep
- Remove conflict markers
- Stage resolved files with
git add - Complete merge with
git commit
Example:
<<<<<<< HEAD
const value = 'my change';
=======
const value = 'their change';
>>>>>>> branch-name
Explain the purpose of Git branches and their importance in collaboration.
Branches allow parallel development without affecting main code. Teams can work on features, fixes, or experiments independently, then merge when ready.
Common workflows:
- Feature branches
- Git Flow
- Trunk-based development
8. Build Tools and Task Runners
What is the purpose of using a build tool like Webpack or Rollup?
- Bundle multiple files into optimized packages
- Transform code (TypeScript, JSX, SASS)
- Optimize assets (minification, compression)
- Enable development features (hot reload, source maps)
- Manage dependencies
How do you configure Webpack for a React or Angular project?
Basic setup includes:
- Entry point specification
- Output configuration
- Loaders for file types (babel-loader for JSX, css-loader)
- Plugins (HtmlWebpackPlugin, optimization plugins)
- Dev server configuration
Example:
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
module: {
rules: [
{
test: /\.jsx?$/,
use: 'babel-loader',
exclude: /node_modules/,
},
],
},
};
Many projects use Create React App or Angular CLI which handle this automatically.
Explain the concept of hot module replacement (HMR) and its benefits.
HMR updates modules in the browser without full page reload, preserving application state.
Benefits:
- Faster development cycle
- Maintains form data and UI state during updates
- See changes instantly without losing context
9. Modern Web Technologies
What is the purpose of Web Components, and how do they work?
Web Components are reusable custom elements built with standard web technologies:
- Custom Elements: Define new HTML tags
- Shadow DOM: Encapsulated styles and markup
- HTML Templates: Reusable markup patterns
They work across frameworks without dependencies.
Example:
class MyComponent extends HTMLElement {
connectedCallback() {
this.innerHTML = '<p>Hello from Web Component!</p>';
}
}
customElements.define('my-component', MyComponent);
Explain the concept of Progressive Web Apps (PWAs) and their advantages.
PWAs are web apps that behave like native apps using:
- Service Workers for offline functionality
- Web App Manifest for installability
- HTTPS for security
Advantages:
- Work offline
- Installable on home screen
- Push notifications
- Fast loading
- Responsive design
- Discoverable via search engines
How do you implement server-side rendering (SSR) in a front-end application?
SSR renders React/Vue components on the server, sending HTML to browser.
Implementations:
- Next.js (React)
- Nuxt.js (Vue)
- Angular Universal
Benefits:
- Faster initial load
- Better SEO
- Improved performance on slow devices
Trade-offs:
- Increased server complexity
- Higher server costs
Example (Next.js):
export async function getServerSideProps() {
const data = await fetchData();
return { props: { data } };
}
export default function Page({ data }) {
return <div>{data.title}</div>;
}