Frontend Flashcards

1
Q

What is the CSS Box Model?

A

The Box Model describes how every HTML element is structured and spaced. It consists of:

  • Content: The actual content of the element.
  • Padding: Space between the content and the border.
  • Border: The edge around the padding.
  • Margin: The space outside the border that separates the element from others.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the Document Object Model (DOM)?

A

The DOM is a tree-like programming interface for web documents where each HTML element is a node. It allows JavaScript to manipulate the document, such as changing styles, adding elements, or handling events.

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

What is event bubbling in JavaScript?

A

Event bubbling is the process where an event starts from the target element and propagates up through its ancestors. For example, a click event on a button inside a div will first trigger the button’s handler, then the div’s.

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

What is Event Capturing in JavaScript?

A

Event capturing is the phase where an event propagates from the root element down to the target element. It occurs before the bubbling phase and allows handling events during this downward propagation.

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

What determines the specificity of CSS rules?

A

Specificity is calculated as:

  • Inline styles (e.g., style=”…”) → Highest specificity.
  • IDs → Higher than classes and attributes.
  • Classes, attributes, and pseudo-classes → Higher than element selectors.
  • Element selectors → Lowest specificity. When multiple rules apply, the one with the highest specificity is used.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between relative and absolute units in CSS?

A
  • Relative Units: Scale based on other elements or settings, for example rem, which is based off of the font size of the root element (<html>), often influcenced by browser settings.
  • Absolute Units: Fixed sizes that don’t scale or adapt, like px (pixels). They remain the same regardless of screen size or user preferences.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the event loop in JavaScript?

A

The event loop allows JavaScript to handle asynchronous tasks (e.g., setTimeout, Promises). It processes tasks from the call stack and the task queue, ensuring the program continues running without blocking.

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

What is a closure in JavaScript?

A

A closure is a function that retains access to its outer scope, even after the outer function has executed. It enables encapsulation and data persistence.

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

What is hoisting in JavaScript?

A

Hoisting moves variable and function declarations to the top of their scope during compilation. Variables declared with var are hoisted but not initialized, while let and const are hoisted but in a “temporal dead zone.”

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

What are promises in JavaScript?

A

A promise in JavaScript is an object that represents the eventual completion (or failure) of an asynchronous operation and its resulting value.

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

How does async/await simplify working with promises?

A

async/await simplifies handling promises by making asynchronous code look synchronous. Using await, execution pauses until the promise resolves or rejects, avoiding the need for .then() chains and improving readability.

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

What is the purpose of CSS media queries?

A

Media queries enable conditional application of styles based on screen size, orientation, resolution, or other properties.

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

Why is semantic HTML important?

A

Semantic HTML uses meaningful tags (e.g., <header>, <article>, <footer>), which improves:

  • Accessibility: Assistive technologies can navigate content more effectively.
  • SEO: Search engines understand content structure better.
  • Readability: Easier to understand for developers.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Debouncing vs. Throttling

A
  • Debouncing: Delays function execution until after the last event (e.g., only triggering a search when the user stops typing for 300ms).
  • Throttling: Ensures a function runs at most once in a specified interval, regardless of how many events occur.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the steps in the browser rendering process?

A
  1. Parse HTML: Build the DOM.
  2. Parse CSS: Create the CSSOM.
  3. Build Render Tree: Combine DOM and CSSOM to include only visible elements with computed styles.
  4. Layout: Calculate size and position of elements in the Render Tree.
  5. Paint: Render pixels on the screen.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is progressive enhancement in web development?

A

Progressive enhancement ensures core functionality, built with basic HTML and CSS, that works across all browsers and versions. Advanced features, added with modern JavaScript or CSS, enhance the experience for users with newer browsers, providing compatibility and improved usability.

17
Q

What is ARIA, and when should it be used?

A

ARIA (Accessible Rich Internet Applications) adds attributes to improve accessibility for screen readers. For example, aria-label=”Submit” provides a description for an unlabeled button.

18
Q

What is Cross-Origin Resource Sharing (CORS)?

A

CORS is a security feature that restricts how resources on a server can be accessed by a client from a different origin. Servers can use headers like Access-Control-Allow-Origin to allow specific origins.

19
Q

What is the critical rendering path?

A

The critical rendering path refers to the sequence of browser actions (HTML, CSS, JS processing) required to render content on the screen as quickly as possible.

20
Q

What is CSP, and why is it important?

A

CSP (Content Security Policy) is a browser feature that prevents attacks like XSS by specifying which sources are allowed for scripts, styles, and other resources. Example:

Content-Security-Policy: script-src 'self'; img-src 'self' https://example.com
21
Q

When is a Promise Object Created?

A
  1. Using the Promise Constructor: Explicitly wrapping logic with new Promise.
  2. APIs That Return Promises: Methods like fetch() or file system operations.
  3. Async Functions: Automatically wraps the return value in a promise.

Key Point: A promise is created whenever an asynchronous operation is initiated or logic is explicitly wrapped in a promise.

22
Q

How Do Promises Work in JavaScript?

A

Resolved or rejected Promises queue their callbacks as microtasks, processed by the event loop right after the call stack is emptied, and before regular tasks, ensuring predictable async execution.

23
Q

How do Promises interact with the event loop?

A

Resolved/rejected Promises queue callbacks as microtasks, executed after the current call stack items but before task queue items.