Unit 4 - Practice Quiz

INT219 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What does "DOM" stand for?

Document Object Model (DOM) structure Easy
A. Document Object Model
B. Dynamic Object Method
C. Document Order Module
D. Data Object Model

2 How does the DOM represent an HTML document?

Document Object Model (DOM) structure Easy
A. As a single, long string of text
B. As a flat list of elements
C. As a CSS stylesheet
D. As a tree-like structure of nodes

3 In the DOM tree, what is the topmost node that serves as the entry point to the page's content?

Document Object Model (DOM) structure Easy
A. The <body> element
B. The document object
C. The window object
D. The <html> element

4 Which JavaScript method is specifically designed to select a single HTML element by its unique id?

DOM traversal and manipulation Easy
A. document.getElementsByTagName()
B. document.getElementsByClassName()
C. document.getElementById()
D. document.querySelector()

5 Which method should you use to select the first element that matches a specific CSS selector, like div.my-class?

DOM traversal and manipulation Easy
A. getElementsByClassName()
B. querySelector()
C. getElementById()
D. querySelectorAll()

6 To change the text inside a <p> tag while ensuring no HTML is rendered, which property is the safest to use?

DOM traversal and manipulation Easy
A. outerHTML
B. innerHTML
C. value
D. textContent

7 How can you change the CSS color property of an element to red using JavaScript?

Dynamic styling and content updates Easy
A. element.css('color', 'red');
B. element.color = 'red';
C. element.style.color = 'red';
D. element.style = 'color: red;';

8 What does the element.classList.add('new-class') method do?

Dynamic styling and content updates Easy
A. It checks if the element has the class new-class.
B. It replaces all existing classes with new-class.
C. It adds the CSS class new-class to the element.
D. It removes the class new-class from the element.

9 What is an "event" in the context of the DOM?

Event propagation and delegation Easy
A. A static property of an HTML element.
B. A signal from the browser that something has happened, like a mouse click or key press.
C. A JavaScript function that runs automatically.
D. An error in the code.

10 What is the default direction of event propagation in modern browsers, where an event travels from the target element up to its ancestors?

Event propagation and delegation Easy
A. Delegation
B. Bubbling
C. Capturing
D. Triggering

11 Which modern JavaScript method is used to attach an event handler (like a function) to an element?

Event propagation and delegation Easy
A. addEventListener()
B. onclick()
C. attachEvent()
D. setHandler()

12 Which browser developer tool panel is primarily used for logging messages and errors from your JavaScript code?

Debugging using browser developer tools Easy
A. Elements
B. Console
C. Network
D. Sources

13 In the developer tools, which panel allows you to inspect and edit the live HTML and CSS of a webpage?

Debugging using browser developer tools Easy
A. Application
B. Elements
C. Console
D. Performance

14 What is the primary purpose of the console.log() function?

Debugging using browser developer tools Easy
A. To output information to the web console for debugging purposes.
B. To display a pop-up alert message to the user.
C. To stop the script from executing at a certain point.
D. To write text directly onto the HTML page.

15 What is the main purpose of a JavaScript module bundler like Webpack or Vite?

Module bundling concepts using modern build tools Easy
A. To run JavaScript code on a server instead of in the browser.
B. To combine multiple JavaScript files into a single, optimized file for the browser.
C. To automatically format JavaScript code to a consistent style.
D. To check JavaScript code for syntax errors.

16 Which of the following is a popular JavaScript module bundler?

Module bundling concepts using modern build tools Easy
A. Webpack
B. ESLint
C. jQuery
D. React

17 What is the main function of a code linter like ESLint?

Code linting and formatting practices Easy
A. To combine multiple code files into a single file.
B. To convert code from a newer to an older version of JavaScript.
C. To analyze code for potential errors and enforce coding standards.
D. To reformat the code's indentation and line breaks.

18 What is the primary role of a code formatter like Prettier?

Code linting and formatting practices Easy
A. To find logical bugs and security vulnerabilities in the code.
B. To minify code for production deployment.
C. To bundle different scripts into a single file.
D. To automatically enforce a consistent code style by reformatting code.

19 Which JavaScript method is used to create a new HTML element from scratch?

DOM traversal and manipulation Easy
A. document.createElement()
B. document.newElement()
C. document.build()
D. document.makeElement()

20 To completely replace an element's content with new HTML content, which property is most suitable?

Dynamic styling and content updates Easy
A. style
B. textContent
C. innerHTML
D. outerText

21 Consider the following HTML snippet:

html
<div id="parent">
<!-- Some comment -->
<p>First paragraph</p>
<span>A span</span>
</div>


What is the difference in output between document.getElementById('parent').childNodes.length and document.getElementById('parent').children.length?

DOM traversal and manipulation Medium
A. Both will return 3.
B. childNodes returns 2, while children returns 3.
C. childNodes returns 3, while children returns 2.
D. childNodes returns 5, while children returns 2.

22 Given the HTML below, if a user clicks on the <p> element, in what order will the alerts fire during the bubbling phase?

html
<div id="grandparent">
<div id="parent">
<p id="child">Click me!</p>
</div>
</div>

<script>
document.getElementById('grandparent').addEventListener('click', () => alert('grandparent'));
document.getElementById('parent').addEventListener('click', () => alert('parent'));
document.getElementById('child').addEventListener('click', () => alert('child'));
</script>

Event propagation and delegation Medium
A. grandparent, parent, child
B. parent, child, grandparent
C. child, parent, grandparent
D. Only 'child' will fire.

23 In the context of a module bundler like Webpack or Vite, what is the primary purpose of 'tree shaking'?

Module bundling concepts using modern build tools Medium
A. To re-render the DOM in a more efficient, tree-like structure.
B. To remove unused code (dead-code elimination) from the final bundle.
C. To dynamically load modules at runtime based on the user's navigation path.
D. To organize project files into a directory tree automatically.

24 What is the key difference between a code linter (like ESLint) and a code formatter (like Prettier)?

Code linting and formatting practices Medium
A. A linter bundles modules, while a formatter minifies the code.
B. A linter compiles code, while a formatter transpiles it.
C. A linter analyzes code for potential errors and bad practices, while a formatter enforces a consistent code style.
D. A linter is for JavaScript only, while a formatter works with HTML and CSS.

25 You need to apply ten different CSS style changes to a single DOM element in response to a user action. Which of the following approaches is generally most performant?

Dynamic styling and content updates Medium
A. Defining a CSS class with all ten styles and adding that class to the element, e.g., element.classList.add('active-state');
B. Setting each style property individually, e.g., element.style.color = 'red'; element.style.fontSize = '16px'; ...
C. Using element.setAttribute('style', 'color: red; font-size: 16px; ...');
D. Setting the innerHTML of the element's parent to recreate the element with a style attribute.

26 You notice a JavaScript function is being called with an incorrect value, but only after it has been executed hundreds of times in a loop. Which debugging feature would be most efficient for pausing execution only when the problematic value appears?

Debugging using browser developer tools Medium
A. A conditional breakpoint with an expression that checks for the incorrect value.
B. Using the 'Pause on exceptions' feature.
C. A standard breakpoint at the start of the function.
D. Logging the value to the console on every iteration.

27 Why is event delegation a recommended pattern for handling events on a large list of items, especially if items are added or removed dynamically?

Event propagation and delegation Medium
A. It ensures that events are handled during the capturing phase instead of the bubbling phase.
B. It attaches a single event listener to a parent element, which improves performance and automatically handles events for new child elements.
C. It stops event propagation completely, preventing memory leaks.
D. It allows each child element to have its own isolated event-handling logic without interfering with others.

28 What is the primary advantage of using document.createDocumentFragment() when appending multiple elements to the DOM?

DOM traversal and manipulation Medium
A. It creates a virtual, off-screen DOM tree, allowing you to append multiple elements with a single reflow/repaint, improving performance.
B. It allows you to create elements that are not visible to the user.
C. It is the only way to create custom HTML elements.
D. It automatically adds event listeners to all child elements that are appended.

29 Which of the following statements accurately describes the relationship between the DOM and an HTML document?

Document Object Model (DOM) structure Medium
A. The DOM is a programming interface (API) that represents the HTML document as a tree-like structure of objects, allowing it to be manipulated by scripts.
B. The DOM is a styling language, similar to CSS, used to apply styles to the HTML document.
C. The HTML document is generated by the browser based on the DOM structure.
D. The DOM is a text file that is an exact copy of the HTML document.

30 What is the key difference between setting an element's textContent versus its innerHTML?

Dynamic styling and content updates Medium
A. innerHTML is faster because it does not parse HTML content.
B. There is no functional difference; they are aliases for the same operation.
C. textContent works only on <p> tags, while innerHTML works on all tags.
D. textContent automatically escapes HTML tags, treating them as plain text, while innerHTML parses and renders them as DOM elements.

31 In a modern front-end build process, what is the typical role of a tool like Babel?

Module bundling concepts using modern build tools Medium
A. To bundle all JavaScript modules into a single file.
B. To format the code according to a predefined style guide.
C. To transpile modern JavaScript (ES6+) code into a backwards-compatible version (like ES5) that older browsers can understand.
D. To analyze the code for potential bugs and programming errors.

32 You have a CSS rule !important that is still being overridden by another style. Where in the Chrome Developer Tools would be the best place to investigate which style is taking precedence and why?

Debugging using browser developer tools Medium
A. The Elements tab, by selecting the element and viewing the 'Computed' and 'Styles' panes.
B. The Network tab, by inspecting the CSS file's headers.
C. The Console tab, by looking for CSS-related error messages.
D. The Sources tab, by placing a breakpoint inside the CSS file.

33 What is the effect of calling event.stopPropagation() inside an event listener?

Event propagation and delegation Medium
A. It stops the event from continuing its propagation journey through the DOM (i.e., it stops bubbling up or capturing down).
B. It removes the event listener from the element after it has fired once.
C. It triggers the same event on all sibling elements.
D. It prevents the default action for that event from occurring (e.g., a link navigating).

34 Given the following JavaScript code, what will the final structure of the <ul> element look like?

html
<ul id="myList">
<li id="item1">Apple</li>
<li id="item2">Banana</li>
</ul>

<script>
const list = document.getElementById('myList');
const item1 = document.getElementById('item1');
const new_item = document.createElement('li');
new_item.textContent = 'Cherry';
list.insertBefore(new_item, item1);
</script>

DOM traversal and manipulation Medium
A. html
<ul id="myList">
<li>Cherry</li>
<li id="item1">Apple</li>
<li id="item2">Banana</li>
</ul>
B. The list will be unchanged.
C. html
<ul id="myList">
<li id="item1">Apple</li>
<li id="item2">Banana</li>
<li>Cherry</li>
</ul>
D. html
<ul id="myList">
<li id="item1">Apple</li>
<li>Cherry</li>
<li id="item2">Banana</li>
</ul>

35 A development team wants to ensure that every time a developer commits code, it is automatically checked for both stylistic consistency and potential logical errors (like using a variable before it's defined). Which combination of tools is best suited for this automated workflow?

Code linting and formatting practices Medium
A. A code formatter (Prettier) and a code linter (ESLint), likely integrated with a pre-commit hook.
B. A JavaScript framework (React) and a CSS preprocessor (Sass).
C. Only a code formatter (Prettier), as it handles all code quality issues.
D. A module bundler (Webpack) and a task runner (Gulp).

36 In the DOM tree, what type of node represents the actual text inside an element like <p>Hello World</p>?

Document Object Model (DOM) structure Medium
A. A CONTENT_NODE
B. A TEXT_NODE
C. An ELEMENT_NODE
D. An ATTRIBUTE_NODE

37 What is the purpose of the dataset property on an HTML element in JavaScript?

Dynamic styling and content updates Medium
A. To store styling information that is an alternative to CSS.
B. To define the type of data that a form input should accept.
C. To access large datasets from a remote server via an API.
D. To get and set custom data attributes (data-*) on an element in a structured way.

38 You are trying to debug a complex layout issue where an element is not sized or positioned as expected. Which feature in browser developer tools would be most helpful for visualizing the element's box model (margin, border, padding, and content)?

Debugging using browser developer tools Medium
A. The box model visualizer, typically found in the Elements tab under the 'Computed' pane.
B. The Network tab, to check if the CSS file loaded correctly.
C. The Console, to log the element's offsetWidth and offsetHeight.
D. The Sources tab, to view the original CSS source code.

39 What problem do module bundlers primarily solve in the context of front-end development?

Module bundling concepts using modern build tools Medium
A. They process and combine many separate JavaScript modules into fewer files (often just one) to optimize for browser loading.
B. They manage the browser's HTTP request-response cycle for the developer.
C. They prevent developers from writing code with syntax errors.
D. They provide a runtime environment for executing JavaScript outside the browser.

40 Consider an element <button id="myBtn">Click</button>. Which JavaScript selector would find the closest ancestor element that has the class container?

DOM traversal and manipulation Medium
A. document.getElementById('myBtn').querySelector('.container')
B. document.getElementById('myBtn').closest('.container')
C. document.getElementById('myBtn').findAncestor('.container')
D. document.getElementById('myBtn').parentNode('.container')

41 Consider the following HTML structure and JavaScript code. What is the final output logged to the console when the child div is clicked?

html
<div id="parent">
<div id="child">Click Me</div>
</div>


javascript
const parent = document.getElementById('parent');
const child = document.getElementById('child');

parent.addEventListener('click', () => console.log('Parent Bubble'), false);
parent.addEventListener('click', () => console.log('Parent Capture'), true);

child.addEventListener('click', (e) => {
console.log('Child Bubble');
e.stopImmediatePropagation();
}, false);

child.addEventListener('click', () => console.log('Child Capture'), true);
child.addEventListener('click', () => console.log('Child Bubble 2'), false);

Event propagation and delegation Hard
A. Parent Capture, Child Capture, Child Bubble, Child Bubble 2, Parent Bubble
B. Parent Capture, Child Capture, Child Bubble, Parent Bubble
C. Parent Capture, Child Capture, Child Bubble
D. Parent Capture, Child Capture, Child Bubble, Child Bubble 2

42 In a Webpack configuration, you are trying to implement long-term caching using [contenthash]. You notice that changing a CSS file also changes the content hash of your main JavaScript entry bundle, even though the JS code itself hasn't changed. What is the most likely cause and solution for this behavior?

Module bundling concepts using modern build tools Hard
A. This is caused by the Webpack runtime and manifest being embedded in the main JS bundle. The solution is to use optimization.runtimeChunk: 'single' to extract the runtime into a separate chunk.
B. Babel is transpiling the CSS import statements in a way that changes the JS output. The solution is to exclude CSS files from babel-loader.
C. The CSS is imported directly into a JavaScript file, making it part of the JS module's dependency graph. The solution is to use optimization.splitChunks to separate CSS.
D. The MiniCssExtractPlugin is configured incorrectly, causing it to inject metadata into the JavaScript bundle. The solution is to ensure the plugin's filename option uses [contenthash].

43 You are tasked with improving the performance of a script that adds 1000 <li> elements to a <ul> in the DOM. Which of the following methods is generally the most performant and why?

Method A: Loop 1000 times, creating an <li> and calling ul.appendChild() in each iteration.
Method B: Loop 1000 times, creating an <li> and appending it to a DocumentFragment, then appending the fragment to the ul once.
* Method C: Build a single string of 1000 <li> elements and set ul.innerHTML with this string.

DOM traversal and manipulation Hard
A. Method B and C have nearly identical performance, but B is safer as it prevents XSS vulnerabilities that can occur with innerHTML.
B. Method B is most performant because it minimizes reflows/repaints by manipulating a detached DOM tree and attaching it only once.
C. Method A is most performant because modern JavaScript engines heavily optimize sequential appendChild calls into a single repaint.
D. Method C is most performant because it involves a single DOM operation and avoids the overhead of creating DOM objects in JavaScript.

44 A script needs to apply several style changes to an element and then read its final dimensions. The code is structured as follows:

javascript
const element = document.getElementById('my-box');
element.style.width = '100px';
element.style.height = '100px';
element.style.opacity = '0.5';

// Read dimensions
const rect = element.getBoundingClientRect();
console.log(rect.width);

element.style.opacity = '1';


Which statement best describes the performance implications of this code?

Dynamic styling and content updates Hard
A. The call to element.getBoundingClientRect() forces a synchronous reflow (layout) to calculate the correct dimensions, negating the browser's ability to batch the preceding style changes.
B. This code causes a memory leak because rect holds a reference to the element's layout properties.
C. The browser will only perform a repaint, not a reflow, because changing opacity does not affect layout.
D. The browser batches all style changes and applies them asynchronously after the script finishes, so there is no performance penalty.

45 While using the Chrome DevTools Performance profiler, you observe a large, solid purple block labeled 'Layout' in the flame chart, which is causing significant UI jank. What is the most effective initial step to diagnose the root cause of this 'forced synchronous layout'?

Debugging using browser developer tools Hard
A. In the 'Performance' tab, find the 'Layout' event, click on it, and inspect the 'Summary' and 'Call Stack' in the details pane to identify the specific JavaScript code that triggered the layout calculation.
B. In the 'Performance' tab, enable the 'Layout Shift Regions' checkbox and re-record to visually identify which elements are moving.
C. Use the 'Memory' tab to take a heap snapshot and look for detached DOM nodes.
D. Add console.log() statements throughout the suspected code paths and re-run the profiler to correlate logs with the purple block.

46 Your team uses ESLint and Prettier, but you encounter a conflict: Prettier formats code in a way that violates an ESLint rule (e.g., max-len). What is the standard, recommended practice for resolving such conflicts and ensuring a smooth developer experience?

Code linting and formatting practices Hard
A. Disable the conflicting ESLint rule manually in the .eslintrc file, as Prettier should always have the final say on formatting.
B. Write a custom Git pre-commit hook that runs prettier --write followed by eslint --fix, committing the result.
C. Configure your code editor to run Prettier first, then ESLint, automatically fixing any issues in that specific order on save.
D. Use the eslint-plugin-prettier and eslint-config-prettier packages. eslint-config-prettier disables conflicting ESLint rules, and eslint-plugin-prettier runs Prettier as an ESLint rule.

47 When an event originating from within a Shadow DOM is dispatched, and it crosses the shadow boundary into the light DOM, what happens to the event.target property as observed by listeners in the light DOM?

Document Object Model (DOM) structure Hard
A. event.target always refers to the original element inside the Shadow DOM, maintaining encapsulation.
B. event.target is retargeted to be the host element of the Shadow DOM to preserve its encapsulation.
C. event.target becomes null or undefined for listeners outside the shadow boundary.
D. An error is thrown because events are not allowed to cross the shadow boundary by default.

48 You're using an ES module-based library and have configured Webpack for tree-shaking. However, you notice that a large, unused portion of the library is still included in your final bundle. The library's package.json does NOT have a "sideEffects" field. Which of the following is the most probable cause for the tree-shaking failure?

Module bundling concepts using modern build tools Hard
A. The library was imported using a dynamic import() expression, which bundlers cannot statically analyze.
B. The library's code contains a top-level function call or modifies a global object (e.g., window.myLib = {}), which is considered a side effect that Webpack cannot safely remove.
C. The library was authored in CommonJS (require/module.exports) and transpiled to ES modules, which often breaks tree-shaking compatibility.
D. Your webpack.config.js is missing the mode: 'production' setting, which is required to enable tree-shaking optimizations.

49 What is a key difference between a NodeList returned by document.querySelectorAll() and an HTMLCollection returned by document.getElementsByTagName() in modern browsers?

DOM traversal and manipulation Hard
A. HTMLCollection is live, meaning it automatically updates if the DOM changes. NodeList from querySelectorAll is static.
B. NodeList is an array, while HTMLCollection is an array-like object.
C. NodeList can only contain Element nodes, while HTMLCollection can contain Element nodes, Text nodes, and Comment nodes.
D. HTMLCollection has a forEach method, while NodeList does not and requires Array.from() to be used for iteration.

50 You are implementing event delegation on a complex list where each <li> contains multiple nested elements. You want to trigger a function only when a click originates specifically on a <span> with the class .icon inside any <li>. Which event handler implementation is the most robust and efficient?

html
<ul id="myList">
<li>Item 1 <span class="icon">X</span></li>
<li>Item 2 <button>Action <span class="icon">Y</span></button></li>
</ul>

Event propagation and delegation Hard
A. javascript
list.addEventListener('click', (e) => {
if (e.target.tagName === 'SPAN' && e.target.classList.contains('icon')) {
// handle click
}
});
B. javascript
list.addEventListener('click', (e) => {
const icon = e.target.closest('.icon');
if (icon && list.contains(icon)) {
// handle click
}
});
C. javascript
list.querySelectorAll('.icon').forEach(icon => {
icon.addEventListener('click', (e) => {
e.stopPropagation();
// handle click
});
});
D. javascript
list.addEventListener('click', (e) => {
if (e.target.className === 'icon') {
// handle click
}
});

51 To achieve a smooth, high-performance animation in JavaScript (e.g., moving an element across the screen), why is using requestAnimationFrame(callback) superior to using setInterval(callback, 16) or a recursive setTimeout(callback, 16)?

Dynamic styling and content updates Hard
A. requestAnimationFrame allows a higher frame rate, up to 120fps, while setInterval is capped at 60fps (~16ms).
B. requestAnimationFrame runs on a separate thread from the main JavaScript thread, preventing the animation from blocking other scripts.
C. requestAnimationFrame callbacks receive a high-resolution timestamp argument, which is necessary for calculating physics-based motion.
D. The browser can optimize animations scheduled with requestAnimationFrame by grouping them into a single reflow/repaint cycle, and it will pause them in inactive tabs, saving CPU and battery life.

52 You're debugging a complex JavaScript application and suspect a specific function, updateState(), is being called with an invalid argument, but only under very specific, hard-to-reproduce conditions. The function is called thousands of times. What is the most efficient way to pause execution only when updateState(arg) is called where arg.id is null?

Debugging using browser developer tools Hard
A. Use a Logpoint at the beginning of updateState() with the expression "Argument:", arg to avoid pausing execution.
B. Set a standard breakpoint at the beginning of updateState() and manually inspect arg each time execution pauses.
C. Place console.log(arg) inside the function and manually watch the console output for a null id.
D. Set a conditional breakpoint at the beginning of updateState() with the condition arg.id === null.

53 What is the primary purpose of the overrides key in an ESLint configuration file (.eslintrc.js) and in what scenario is it most critically used?

Code linting and formatting practices Hard
A. To override the severity of a specific rule from "error" to "warn" for the entire project.
B. To define global variables that ESLint should not flag as undefined, like $ for jQuery.
C. To specify a different parser, like @typescript-eslint/parser, for the entire project instead of the default.
D. To apply a different set of rules for a specific list of files or file glob patterns, such as having stricter rules for test files.

54 Which of these statements accurately describes the relationship between the DOM, CSSOM, and the Render Tree?

Document Object Model (DOM) structure Hard
A. The DOM and CSSOM are parsed independently and have no direct relationship; the browser uses them separately to paint the page.
B. The Render Tree is created by combining the DOM and CSSOM; it includes only the nodes that are visually rendered, so elements like <head> or those with display: none; are excluded.
C. The CSSOM is a part of the DOM, representing style information as attributes on DOM nodes.
D. The Render Tree is a direct 1:1 copy of the DOM tree, with style information attached to each node from the CSSOM.

55 In the context of Webpack, what is the fundamental difference between a loader and a plugin?

Module bundling concepts using modern build tools Hard
A. Loaders are used for transpiling JavaScript (e.g., Babel), while plugins are used for handling other asset types like CSS and images.
B. Loaders operate on individual files as they are being added to the dependency graph, while plugins operate on the bundle as a whole at various points in the compilation lifecycle.
C. Loaders are officially maintained by the Webpack team, while plugins are exclusively third-party additions.
D. Plugins are configured in the module.rules array of the Webpack config, whereas loaders are configured in the top-level plugins array.

56 Given the following HTML snippet, what will el.querySelector(':scope > .c') select, where el is the DOM element with the ID a?

html
<div id="a">
<div class="c">
<!-- C1 -->
<div class="b">
<div class="c"></div> <!-- C2 -->
</div>
</div>
<div class="b">
<div class="c"></div> <!-- C3 -->
</div>
</div>

DOM traversal and manipulation Hard
A. It will select only the div commented with C1.
B. It will select the divs commented with C1 and C3.
C. It will select all three divs with class c.
D. It will throw a syntax error because :scope is not valid in querySelector.

57 What is the primary difference between setting an element's opacity to 0 and setting its display to none?

Dynamic styling and content updates Hard
A. Both make the element invisible and remove it from the document layout flow.
B. display: none is animatable using CSS transitions, whereas opacity: 0 is not.
C. opacity: 0 makes the element invisible but it still occupies its space in the layout and can receive events. display: none removes the element from the layout flow and it cannot receive events.
D. opacity: 0 removes the element from the accessibility tree, while display: none does not.

58 Under what specific circumstance would you need to use pointer-events: none; in CSS as part of a complex event delegation strategy?

Event propagation and delegation Hard
A. To disable CSS hover effects on an element.
B. When an element (e.g., a decorative overlay <div>) is positioned on top of another element that needs to be clickable, allowing clicks to 'pass through' the overlay to the element below.
C. To prevent an element from triggering any JavaScript events whatsoever.
D. To improve rendering performance by telling the browser it doesn't need to calculate hit-testing for the element.

59 What is the primary purpose of a 'source map' (.js.map file) generated by a build tool like Webpack, and how does it relate to debugging?

Module bundling concepts using modern build tools Hard
A. It is a JSON file that maps the code within a bundled/minified/transpiled file back to its original position in the source files, allowing developers to debug their original code in the browser.
B. It provides metadata for package managers like NPM to resolve module versions correctly.
C. It is a map of all dependencies in the project, used by the bundler for tree-shaking.
D. It is a lightweight version of the bundle used during development for faster hot module replacement (HMR).

60 Consider the following code intended to remove all child nodes from a div with the id container. Why is the first approach problematic, while the second one works correctly?

javascript
// Approach 1 (Problematic)
const container1 = document.getElementById('container');
const children1 = container1.children;
for (let i = 0; i < children1.length; i++) {
container1.removeChild(children1[i]);
}

// Approach 2 (Correct)
const container2 = document.getElementById('container');
while (container2.firstChild) {
container2.removeChild(container2.firstChild);
}

DOM traversal and manipulation Hard
A. Approach 2 is inefficient because container.firstChild causes a reflow in every iteration of the loop.
B. Approach 1 fails because container.children returns a live HTMLCollection. As children are removed, the collection shrinks and children.length changes, causing the loop to terminate prematurely and skip elements.
C. Approach 1 throws an error because you cannot iterate and modify a collection at the same time.
D. Approach 1 fails because children is a static NodeList, which doesn't update during the loop.