FrontendInterviewPrepKit(Sample)
FrontendInterviewPrepKit(Sample)
Frontend Interview
Kit - Parikh Jain
Hello and welcome! I'm Parikh Jain, and I'm excited to share with you the ultimate
guide to mastering frontend interviews. This kit is a labor of love, drawn from my
extensive journey as an SDE at Amazon, a founding member at Coding Ninjas, and
the founder of Propeers. I’ve distilled my real-world experience into a
comprehensive resource that covers every topic you need to excel.
Angular Interview Questions With Solutions & Code Snippets (20 questions)
Vue JS Interview Questions With Solutions & Code Snippets ( 20 questions)
Performance Optimization & Best Practices With Solutions & Code Snippets(20 Questions)
Machine Coding Round Questions With Solutions And Code Snippets - Frontend (20
questions)
50+ Important Code snippets for Frontend Developer (HTML, CSS, Javascript, React,
Angular, Vue)
DSA Questions For Frontend Developer With Leetcode links ( 100 questions)
All-In-One Resource:
From foundational topics to advanced problem-solving, every page is
designed to give you a competitive edge.
Interview Confidence:
Let’s Start
HTML & CSS Interview Questions With Solutions & Code Snippets
(25 Questions)
Sample Question 1: How do you create a responsive navigation bar using HTML
& CSS? (Intermediate)
Answer:
A responsive navigation bar typically uses semantic <nav> elements, lists for menu
items, and media queries to adapt styles for different screen sizes. Techniques
like Flexbox are often employed to align items.
Code Example:
<nav class="navbar">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
.navbar ul {
display: flex;
list-style: none;
padding: 0;
}
.navbar li {
margin-right: 20px;
}
@media (max-width: 600px) {
.navbar ul {
flex-direction: column;
}
.navbar li {
margin: 10px 0;
}
}
Sample Question 2: How does CSS specificity work when combining selectors,
and how can you override styles defined with high specificity, such as inline
styles? (Hard)
Answer:
CSS specificity is calculated based on the number of ID selectors, class selectors,
and element selectors used. Inline styles have the highest specificity. To override
styles with high specificity, you can use the !important flag or create a selector with
higher specificity, though this should be done sparingly.
Code Example:
Event bubbling occurs when an event propagates from the target element up
through its ancestors. Capturing is the reverse process, where events are
handled from the outer elements down to the target element.
Code Example:
// Capturing phase
document.getElementById("child").addEventListener("click", () => {
Answer:
Code Example:
function memoize(fn) {
const cache = {};
return function(...args) {
const key = JSON.stringify(args);
if (cache[key]) {
return cache[key];
}
const result = fn(...args);
cache[key] = result;
return result;
}
}
const factorial = memoize(function(n) {
if (n === 0) return 1;
return n * factorial(n - 1);
});
console.log(factorial(5)); // 120
Answer: Generator functions can pause and resume execution using the yield
keyword. They return an iterator that produces a sequence of values on
demand.
Code Example:
function* numberGenerator() {
let num = 0;
while (true) {
yield num++;
}
}
const gen = numberGenerator();
console.log(gen.next().value); // 0
console.log(gen.next().value); // 1
Code Example:
const myIterable = {
data: [1, 2, 3],
[Symbol.iterator]() {
let index = 0;
const data = this.data;
return {
next() {
Code Example:
2. Sample Question: How does the React Context API work for managing
global state? (Intermediate)
Answer:
The Context API provides a way to pass data through the component tree
without having to pass props down manually at every level. It’s useful for
global data like themes, user authentication, or language settings.
Code Example:
Code Example:
2. Question: How does lazy loading work in Angular and why is it beneficial?
(Intermediate)
Answer: Lazy loading loads feature modules only when needed, reducing the
initial bundle size and improving application startup performance.
Code Example:
1. Sample Question: How do you pass data from a parent component to a child
component in Vue? (Intermediate)
Answer:
Data is passed from a parent to a child using props. The child component
declares the props it expects, and the parent binds data to those props.
Code Example:
// Parent Component
// In a Vue component
const AsyncComponent = () => import('./components/AsyncComponent.vu
e');
export default {
components: {
AsyncComponent
},
template: `<AsyncComponent />`
}
// .eslintrc.json
{
"env": {
"browser": true,
"node": true,
"es6": true},
"extends": "eslint:recommended",
"rules": {
"semi": ["error", "always"],
"quotes": ["error", "single"]
}
}
// main.js
const worker = new Worker('worker.js');
worker.postMessage('Start processing');
worker.onmessage = function(event) {
console.log('Result:', event.data);
};
// worker.js
onmessage = function(event) {
// Perform heavy computation here
postMessage('Processing complete');
Answer: Optimize animations by using CSS transforms and opacity (which are
GPU-accelerated), avoiding layout changes during animations, and preferring CSS
animations over JavaScript when possible.
Code Example:
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.animated {
animation: fadeIn 0.5s ease-in-out;
}
1
. Countdown Timer
Problem:
Implement a countdown timer that counts down to a specified future date.
Solution:
HTML:
JavaScript:
──────────────────────────────
Infinite Scrolling with Lazy Loading
Plain Implementation:
HTML:
<div id="infinite-scroll-container">
<ul id="item-list"></ul>
</div>
CSS:
#infinite-scroll-container {
height: 400px;
overflow-y: auto;
border: 1px solid #ccc;
padding: 10px;
}
#item-list li {
margin-bottom: 20px;
}
#item-list img {
width: 100%;
display: block;
opacity: 0;
transition: opacity 0.5s ease-in;
}
#item-list img.visible {
opacity: 1;
}
let page = 1;
const loadItems = async () => {
// Simulated API call (replace with actual API)
for (let i = 0; i < 10; i++) {
const li = document.createElement('li');
li.innerHTML = `
<h4>Item ${page * 10 + i}</h4>
<img data-src="https://via.placeholder.com/400x200?text=Item+${page
* 10 + i}" alt="Item Image">
`;
list.appendChild(li);
}
lazyLoadImages();
page++;
};
// Initial load
loadItems();
React Implementation:
// InfiniteScroll.jsx
import React, { useState, useEffect, useRef } from 'react';
function InfiniteScroll() {
const [items, setItems] = useState([]);
const [page, setPage] = useState(1);
const containerRef = useRef(null);
useEffect(() => {
loadItems();
}, []);
return (
<divid="infinite-scroll-container"
ref={containerRef}
style={{ height: '400px', overflowY: 'auto', border: '1px solid #ccc', padding: '
onScroll={handleScroll}
>
Sample 1
. Closure Example
javascript
Copy
function counter() {
let count = 0;
return function() {
count++;
return count;
};
Sample 2
. Mapping Over an Array in React
Generates a list from an array.
jsx
Copy
function FruitList({ fruits }) {
return (
<ul>
{fruits.map((fruit, index) => <li key={index}>{fruit}</li>)}
</ul>
);
}
──────────────────────────────