Interview Questions Practice Flashcards

(70 cards)

1
Q

Explain the difference between <span> and <div>. When would you use one over the other?</span>

A

<div>: Block-level, takes full width, usually for layout/sections.

<span>: Inline-level, takes content width, usually for styling small text parts.
</span></div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is semantic HTML and why is it important? Give examples of semantic tags.

A

Using HTML tags based on their meaning, not just appearance (e.g., <header>, <nav>, <article>, <footer>).

Importance: Better for SEO, accessibility, and code readability/maintainability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you ensure your HTML is accessible? What are ARIA attributes?

A

Ensure: Use semantic HTML, proper heading structure, alt text for images, and meaningful link text.

ARIA (Accessible Rich Internet Applications): Attributes (role, aria-label, aria-describedby) to enhance semantics for assistive technologies when native HTML isn’t enough (e.g., custom widgets).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe the purpose of the <!DOCTYPE html> declaration.

A

A declaration telling the browser to render the page in “standards mode” (modern HTML5). Essential for consistent rendering.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain the CSS Box Model. How does box-sizing: border-box; change it?

A

HTML elements are boxes with Content, Padding (space around content), Border, and Margin (space outside border).

box-sizing: border-box;: Includes padding and border within the element’s specified width/height, simplifying sizing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe the concept of CSS specificity. How is it calculated?

A

A set of rules determining which CSS declaration applies when multiple rules target the same element.

Calculated by (highest to lowest priority): Inline Style > ID > Class/Attribute/Pseudo-class > Element/Pseudo-element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between margin and padding?

A

padding: Space inside the element, between content and border. Affects the element’s background color.

Margin: Space outside the element’s border, pushing other elements away. Transparent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain different CSS positioning properties (static, relative, absolute, fixed, sticky). When would you use each?

A

static: Default; normal flow, top/left no effect.

relative: Positioned relative to its normal flow. top/left moves it from its original spot.

absolute: Positioned relative to its nearest positioned ancestor (not static). Removed from flow.

fixed: Positioned relative to the viewport. Stays put on scroll.

sticky: Behaves relative until a scroll threshold, then fixed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are Flexbox and CSS Grid? When would you choose one over the other?

A

Flexbox: 1-dimensional layout (row OR column). Good for aligning items in a line or distributing space.

CSS Grid: 2-dimensional layout (rows AND columns). Good for overall page layout, creating complex grids.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can you optimize your CSS for performance? (e.g., critical CSS, purging unused CSS)

A

Critical CSS: Inline essential CSS for above-the-fold content to render quickly.

Purge Unused CSS: Remove styles not used on the page (e.g., with PurgeCSS).

Minify CSS, avoid @import, and use efficient selectors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are pseudo-classes and pseudo-elements? Give examples.

A

Pseudo-classes (:): Target elements based on a state (e.g., :hover, :focus, :first-child).

Pseudo-elements (::): Target parts of an element (e.g., ::before, ::after, ::first-letter).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you handle responsive design using CSS? (Media queries, vw/vh, percentages, min-width/max-width).

A

Media Queries (@media): Apply styles based on device characteristics (screen width, height, orientation).

Fluid Units: Use vw/vh, percentages for flexible sizing.

min-width/max-width: Control element scaling within ranges.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Explain the difference between null and undefined.

A

undefined: Variable declared but no value assigned, or a missing function argument/object property. Represents the absence of value.

null: Explicitly assigned value representing “no value” or “empty.” A primitive value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the event loop in JavaScript? How does it work?

A

JS is single-threaded but non-blocking. The event loop continuously checks the call stack and moves tasks from the message queue (e.g., setTimeout callbacks, DOM events) to the stack when it’s empty.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe the difference between == and ===.

A

== (Loose equality): Compares values after type coercion (tries to convert types).

=== (Strict equality): Compares values and types without coercion. (Always prefer ===).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are closures in JavaScript? Provide an example of where they might be useful.

A

A function “remembers” and can access variables from its outer (enclosing) scope, even after the outer function has finished executing.

Use: Data privacy, creating factory functions, and currying.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Explain Hoisting in JavaScript.

A

JavaScript’s default behavior of moving declarations (variables like var, functions) to the top of their containing scope during compilation.

Note: Only declarations are hoisted, not initializations (let/const are hoisted but in a “temporal dead zone”).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is this in JavaScript? How does its value change? (And discuss call, apply, bind).

A

this: A keyword whose value refers to the object executing the current function.

Value depends on how the function is called: Global object (browser window), object owning the method, new instance (constructor), specific object (call/apply/bind), or undefined in strict mode for standalone functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Describe Promises and async/await. Why are they used?

A

Promises: Objects representing the eventual completion (or failure) of an asynchronous operation and its resulting value. (.then(), .catch(), .finally()).

async/await: Syntactic sugar built on Promises, making asynchronous code look and behave more like synchronous code, improving readability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is event bubbling and event capturing? How can you prevent them?

A

When an event occurs on an element:
Capturing (down): Event propagates from the window down to the target element.

Bubbling (up): Event propagates from the target element up to the window (default behavior).
Prevent: event.stopPropagation().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Explain the concept of prototypal inheritance in JavaScript.

A

Objects in JS inherit properties and methods from other objects via a prototype chain. When you access a property, JS looks for it on the object, then its prototype, then its prototype’s prototype, etc., until found or null is reached.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What are array methods? (e.g., map, filter, reduce, forEach). When would you use each?

A

map: Creates a new array by calling a function on every element in the original array. (Transforms elements).

filter: Creates a new array with only elements that pass a test (return true). (Selects elements).

reduce: Executes a reducer function on each element, resulting in a single output value. (Aggregates elements).

forEach: Executes a provided function once for each array element. (Iterates, no new array returned).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How does event delegation work? Why is it beneficial?

A

Attaching a single event listener to a parent element instead of multiple listeners to individual child elements.

Benefit: Efficient for dynamic lists, reduces memory usage, simplifies code. Uses event bubbling.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Explain debouncing and throttling. When would you use them?

A

Debouncing: Delays function execution until after a certain period of inactivity (e.g., search bar input, window resize). Only the last call in a series triggers.

Throttling: Limits how often a function can be called within a given time frame (e.g., scroll events, button clicks). Guarantees execution at regular intervals.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Why use a front-end framework/library? What problems do they solve?
Solves common problems: State management, component reuse, routing, UI updates. Benefits: Speeds development, improves maintainability, enhances user experience, enforces structure.
26
Explain the concept of component-based architecture.
Building UIs from small, independent, reusable, and encapsulated pieces (components) that manage their own state and rendering.
27
What is the Virtual DOM (if applicable to the framework)? How does it improve performance?
An in-memory lightweight representation of the actual DOM. Improvement: Frameworks compare old vs. new Virtual DOM, calculate minimal changes, then update only the necessary parts of the real DOM, improving performance.
28
Describe the component lifecycle. (e.g., mounting, updating, unmounting).
A series of phases a component goes through from creation to destruction: Mounting (creation, insertion into DOM), Updating (re-rendering due to state/prop changes), Unmounting (removal from DOM).
29
How do you handle state management in your preferred framework? (e.g., Redux, Vuex, Context API, NgRx).
Managing data that changes over time and affects component rendering. Methods: Component local state (e.g., useState), context APIs, global stores (e.g., Redux, Vuex, NgRx).
30
How do you pass data between components? (props, events, context, services).
Parent to Child: Props (attributes passed down). Child to Parent: Callback functions passed as props, triggering parent state updates. Siblings/Any: Global state managers, Context API, event buses, service injection.
31
What are hooks (in React)? Why were they introduced?
Functions (useState, useEffect) that let you "hook into" React features (state, lifecycle) directly from functional components. Why: Enable functional components to have state/side effects, remove need for class components, improve code reuse and readability.
32
What are functional components vs. class components? When would you use each (or why prefer one now)?
Class: ES6 classes, manage state and lifecycle with this and lifecycle methods. (Older style, generally less used for new code). Functional: Plain JS functions, manage state and lifecycle using Hooks. (Modern React, simpler, better performance potential).
33
Explain useState and useEffect.
useState: Hook for adding state variables to functional components. Returns [state, setState]. useEffect: Hook for performing side effects (data fetching, DOM manipulation, subscriptions) in functional components. Runs after every render, or conditionally.
34
How do you optimize performance in React applications? (Memoization, useCallback, useMemo).
Memoization: Preventing re-renders if props/state haven't changed. useCallback: Memoizes a function instance, preventing unnecessary re-creation on re-renders, useful for passing down to memo-ized children. useMemo: Memoizes a value (result of a calculation), recalculates only if dependencies change.
35
What is reconciliation?
React's process of comparing the new Virtual DOM tree with the old one to find the minimum number of changes needed to update the real DOM.
36
How do you handle routing in React applications?
Using a library like React Router (react-router-dom) to map URLs to specific components and manage navigation.
37
Describe higher-order components (HOCs) or render props.
HOCs: Functions that take a component and return a new component with enhanced props/behavior (e.g., withRouter). Render Props: A pattern where a component receives a function via a prop, which it calls to render its children, enabling flexible shared logic.
38
How do you measure and improve web performance? (Core Web Vitals, Lighthouse).
Measure: Tools like Lighthouse, PageSpeed Insights (Google), WebPageTest, browser DevTools. Focus on Core Web Vitals (LCP, FID, CLS). Improve: Image optimization, lazy loading, code splitting, minification, critical CSS, caching.
39
What is lazy loading? How can you implement it for images, components, or routes?
Loading resources (images, components, routes) only when they are needed or are about to enter the viewport, rather than all at once. Implement: loading="lazy" for images, dynamic import() for JS modules/components, Intersection Observer API.
40
Explain tree shaking.
A build optimization that eliminates dead code (unused exports) from your final JavaScript bundle. Reduces bundle size.
41
How do you optimize assets (images, fonts, videos) for the web?
Images: Choose correct formats (WebP, AVIF), compress, responsive images (srcset/sizes), lazy load. Fonts: Host locally, subset, font-display. Videos: Compress, stream, use
42
What is the critical rendering path? How can you optimize it?
The sequence of steps a browser takes to convert HTML, CSS, and JavaScript into pixels on the screen. Optimize: Prioritize critical resources, minify, defer non-critical JS/CSS.
43
Describe the difference between render-blocking and non-render-blocking resources.
Render-blocking: Resources (CSS, synchronous JS) that must be processed before the browser can render the page content. Non-render-blocking: Resources that can be loaded asynchronously without delaying initial page render (e.g., defer/async scripts).
44
How do you handle network requests efficiently? (Caching, service workers).
Caching: Store frequently accessed resources (images, CSS, JS) in the browser's cache to reduce network requests on subsequent visits. (HTTP caching headers). Service Workers: A JavaScript file that runs in the background, intercepting network requests to provide offline capabilities, robust caching strategies (Cache API), and push notifications.
45
What is a build tool (e.g., Webpack, Vite, Parcel)? Why do we need them?
Purpose: Automate repetitive tasks for front-end code (bundling, transpiling, minifying, optimizing assets). Why: Transforms source code into production-ready code, improves performance, enables modern JS features.
46
Explain the purpose of transpilers (e.g., Babel) and polyfills.
Transpiler (e.g., Babel): Converts modern JS code (e.g., ES6+) into older, widely supported JS (e.g., ES5) for broader browser compatibility. Polyfills: Pieces of code that provide modern browser functionality (e.g., Promise) in older browsers that don't natively support it.
47
What is version control (e.g., Git)? Describe your typical Git workflow.
Git: A distributed version control system for tracking changes in source code during software development. Workflow (e.g., Feature Branching): Create branches for new features, commit changes, push to remote, create pull requests for review, merge into main/develop.
48
What is a package manager (npm, yarn)? What problem do they solve?
Purpose: Tools (Node Package Manager, Yarn) for managing project dependencies (libraries, frameworks). Problem Solved: Automates downloading, installing, updating, and removing external code packages, ensuring consistent environments and managing versions.
49
How do you ensure code quality? (Linters, formatters, unit tests).
Linters (ESLint): Analyze code for potential errors, stylistic issues, and adherence to coding standards. Formatters (Prettier): Automatically reformat code to a consistent style. Unit Tests: Verify individual functions or components work as expected (see Testing section).
50
Why is testing important in front-end development?
Ensures code quality, reduces bugs, prevents regressions, improves confidence in deployments, speeds up development in the long run, and serves as documentation.
51
What are different types of tests (unit, integration, end-to-end)? When would you use each?
Unit: Tests small, isolated parts of code (e.g., single function, component). Fast, precise error location. Integration: Tests how multiple units work together (e.g., two components interacting, API calls). End-to-End (E2E): Simulates real user interaction with the full application (e.g., logging in, navigating). Slowest, highest confidence.
52
What testing frameworks are you familiar with? (e.g., Jest, React Testing Library, Cypress, Playwright).
Jest: Popular JS test runner, often used for unit/integration tests (especially with React). React Testing Library: Focuses on testing component behavior from a user's perspective, rather than implementation details. Cypress/Playwright: E2E testing frameworks that automate browser interactions.
53
How do you write a good unit test for a component?
Focus: Test the component's output given specific inputs (props/state) and user interactions. Principles: Isolated, deterministic, fast, readable, and covers expected behavior and edge cases. (e.g., using render, fireEvent, expect assertions).
54
How do you ensure your website works across different browsers?
Methods: Test in major browsers, use CSS prefixes (or Autoprefixer), use transpilers/polyfills (Babel), use feature detection (Modernizr), consult Can I use...?. Goal: Consistent functionality and appearance across different browsers.
55
What is progressive enhancement and graceful degradation?
Progressive Enhancement: Start with a basic, accessible, core experience for all, then add more advanced features for modern browsers/capable devices. (Build up). Graceful Degradation: Build a full-featured version for modern browsers, then ensure it degrades gracefully (still functional, maybe less pretty) for older browsers. (Build down).
56
Why is web accessibility important? How do you ensure your applications are accessible?
Importance: Ensures everyone, including people with disabilities (visual, motor, cognitive), can perceive, understand, navigate, and interact with your website. Legal requirement and ethical responsibility. Ensure: Semantic HTML, ARIA attributes, keyboard navigation, sufficient color contrast, meaningful alt text, proper focus management.
57
What are some common accessibility pitfalls?
Lack of alt text for images, poor color contrast, inaccessible forms (missing labels), reliance solely on mouse interactions, improper heading structure, non-descriptive link text.
58
What are some common front-end design patterns you're familiar with? (e.g., Module, Revealing Module, Observer, Singleton).
Module Pattern: Encapsulates code to prevent global scope pollution, creating private/public members. Revealing Module Pattern: Variation of module pattern that explicitly "reveals" public methods. Observer Pattern: Defines a one-to-many dependency, where objects (observers) are notified of changes to another object (subject). Singleton Pattern: Ensures a class has only one instance and provides a global point of access to it. Container/Presentational (Dumb/Smart Components): Separates concerns between UI logic (presentational) and data/state management (container).
59
How do you structure your front-end projects? (e.g., feature-based, layer-based).
Feature-based: Organize files by feature (e.g., src/features/Auth, src/features/Products). Layer-based: Organize by type (e.g., src/components, src/services, src/pages). Considerations: Scalability, team size, project complexity, ease of navigation.
60
What are the principles of good component design?
Single Responsibility Principle (SRP): Each component does one thing well. Reusability: Design for use in multiple contexts. Encapsulation: Internal logic/state is isolated. Testability: Easy to test independently. Maintainability: Clear, readable, and easy to modify. Separation of Concerns: Keep UI logic separate from business logic.
61
Tell me about a challenging front-end project you worked on. What were the challenges and how did you overcome them?
Focus: Describe a real challenge (tech, team, deadline), your specific role, actions taken, and the positive outcome/learnings. Emphasize problem-solving process.
62
How do you stay up-to-date with the latest front-end technologies?
Read blogs (CSS-Tricks, Smashing Magazine), follow industry leaders on social media, attend conferences/meetups, online courses, personal projects, read documentation, explore new libraries.
63
Describe your development workflow from start to finish.
Example: Requirements gathering -> Design/Wireframing -> Feature branching (Git) -> Coding (TDD approach) -> Unit/Integration testing -> Code review -> Deployment -> Monitoring/Maintenance.
64
How do you approach debugging a problem in a front-end application?
Methodical: Reproduce the bug -> Isolate the problem (binary search, commenting) -> Use browser DevTools (console, network, elements, debugger) -> Check logs -> Consult documentation/community -> Test fix.
65
What's your experience with collaborative development? How do you handle code reviews?
Collaborative: Use Git, clear communication, break down tasks, pair programming. Code Reviews: Provide constructive feedback (positive and critical), focus on code quality, performance, best practices, maintainability; be open to receiving feedback.
66
Imagine a scenario where a user reports that a part of your application is not loading. How would you debug this?
Check: Browser console (errors?), network tab (failed requests?), server logs. Isolate: Check specific component/route, inspect network calls for that part. Is it JS error, network issue, server error, or resource missing?
67
What are data attributes (data-*) and when would you use them?
Custom attributes (data-id="123", data-state="active") to store private data directly on HTML elements. Use: For JavaScript to easily access and manipulate element-specific data without relying on classes/IDs for storage.
68
What is Dynamic and Static Typing in programming?
Static Typing: Types are checked before the program runs (at compile time), catching type errors early and requiring explicit type declarations for variables. Dynamic Typing: Types are checked while the program runs (at runtime), allowing variables to hold different types of data without explicit declaration.
69
What are Primitive Types in Js?
- Undefined - Null - Boolean - Number - Strings - Symbols
70
What are APIs?
APIs establish a set of rules and protocols that allow software applications to communicate with each other and exchange data efficiently.