1Which data structure best describes the Document Object Model (DOM)?
A.Stack
B.Tree
C.Queue
D.Hash Map
Correct Answer: Tree
Explanation:The DOM is represented as a tree structure where the document is the root node, and every other element, attribute, and piece of text is a node connected to it.
Incorrect! Try again.
2What is the return type of the method document.getElementById('header') if the element exists?
A.HTMLCollection
B.NodeList
C.HTMLElement
D.Array
Correct Answer: HTMLElement
Explanation:getElementById returns a single HTMLElement object (specifically an object inheriting from it) representing the element with the specified ID, or null if it is not found.
Incorrect! Try again.
3Which method is used to select the first element that matches a specific CSS selector?
A.document.querySelectorAll()
B.document.getElementsByClassName()
C.document.querySelector()
D.document.getElement()
Correct Answer: document.querySelector()
Explanation:document.querySelector() returns the first Element within the document that matches the specified selector, or null if no matches are found.
Incorrect! Try again.
4When using document.querySelectorAll(), what type of collection is returned?
A.A standard JavaScript Array
B.A static NodeList
C.A live HTMLCollection
D.A JSON Object
Correct Answer: A static NodeList
Explanation:querySelectorAll returns a static (non-live) NodeList. Unlike HTMLCollection, it does not automatically update if the DOM changes after the variable is assigned.
Incorrect! Try again.
5Which property allows you to access the text content of a node and its descendants, while being aware of CSS styling (like display: none)?
A.innerHTML
B.textContent
C.innerText
D.nodeValue
Correct Answer: innerText
Explanation:innerText is aware of CSS styling and will not return text for elements that are hidden (e.g., display: none), whereas textContent returns text from all elements regardless of styling.
Incorrect! Try again.
6What is the primary security risk associated with using innerHTML to insert user-generated content?
A.Cross-Site Request Forgery (CSRF)
B.Cross-Site Scripting (XSS)
C.SQL Injection
D.Memory Leaks
Correct Answer: Cross-Site Scripting (XSS)
Explanation:Using innerHTML parses the content as HTML. If user input contains malicious <script> tags, the browser may execute them, leading to XSS attacks.
Incorrect! Try again.
7To traverse to the immediate parent of a specific DOM node, which property should be used?
A.node.previousSibling
B.node.parentNode
C.node.childNodes
D.node.ancestor
Correct Answer: node.parentNode
Explanation:The parentNode property returns the DOM node that is the parent of the current node.
Incorrect! Try again.
8Which method creates a new HTML element node in memory but does not attach it to the DOM tree?
A.document.append()
B.document.createElement()
C.document.createTextNode()
D.document.render()
Correct Answer: document.createElement()
Explanation:document.createElement('tagName') creates a new element node with the specified tag name, but it must be manually appended to the DOM using methods like appendChild.
Incorrect! Try again.
9If you want to place a new node newNode directly before an existing node referenceNode within a parent parentNode, which method matches the syntax: ?
A.appendChild
B.insertBefore
C.prepend
D.replaceChild
Correct Answer: insertBefore
Explanation:The syntax parentNode.insertBefore(newNode, referenceNode) inserts the newNode immediately before the referenceNode as a child of parentNode.
Incorrect! Try again.
10Which property is best used to toggle a CSS class on an element?
A.element.className.toggle()
B.element.style.toggle()
C.element.classList.toggle()
D.element.setAttribute('class')
Correct Answer: element.classList.toggle()
Explanation:The classList property provides a toggle() method which adds the class if it is not present, and removes it if it is present.
Incorrect! Try again.
11How do you modify a CSS variable (custom property) named --main-color on the root element using JavaScript?
Explanation:CSS variables are modified using style.setProperty(). The root element is accessed via document.documentElement.
Incorrect! Try again.
12Which method retrieves the final values of all CSS properties of an element after applying active stylesheets and computing values?
A.element.style
B.window.getComputedStyle(element)
C.document.getCSS(element)
D.element.currentStyle
Correct Answer: window.getComputedStyle(element)
Explanation:window.getComputedStyle(element) returns an object containing the values of all CSS properties of an element, after applying active stylesheets and resolving computations.
Incorrect! Try again.
13In the context of the DOM, what is the difference between children and childNodes?
A.children contains only Element nodes; childNodes contains all node types (text, comments, elements).
B.children is a static list; childNodes is a live list.
C.children includes text nodes; childNodes includes only HTML tags.
D.There is no difference; they are aliases.
Correct Answer: children contains only Element nodes; childNodes contains all node types (text, comments, elements).
Explanation:children returns an HTMLCollection of element nodes only. childNodes returns a NodeList containing all child nodes, including whitespace text nodes and comments.
Incorrect! Try again.
14Which attribute allows you to store custom data on an HTML element, accessible via the dataset property in JavaScript?
A.meta-*
B.data-*
C.aria-*
D.custom-*
Correct Answer: data-*
Explanation:Attributes starting with data- (e.g., data-user-id) are standard for custom data storage and are accessible via element.dataset.userId.
Incorrect! Try again.
15What are the three phases of event propagation in the correct order?
A.Target, Bubbling, Capturing
B.Capturing, Target, Bubbling
C.Bubbling, Target, Capturing
D.Target, Capturing, Bubbling
Correct Answer: Capturing, Target, Bubbling
Explanation:Events first go down the DOM tree (Capturing), reach the target element (Target), and then bubble up the DOM tree (Bubbling).
Incorrect! Try again.
16Which method is used to stop an event from bubbling up the DOM tree?
A.event.preventDefault()
B.event.stopPropagation()
C.event.stopImmediatePropagation()
D.event.halt()
Correct Answer: event.stopPropagation()
Explanation:event.stopPropagation() prevents further propagation of the current event in the capturing and bubbling phases.
Incorrect! Try again.
17What is the purpose of event.preventDefault()?
A.It stops the event from reaching parent elements.
B.It prevents the browser's default behavior associated with the event (e.g., submitting a form).
C.It removes the event listener after one execution.
D.It pauses the JavaScript execution.
Correct Answer: It prevents the browser's default behavior associated with the event (e.g., submitting a form).
Explanation:preventDefault() tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be.
Incorrect! Try again.
18What is Event Delegation?
A.Creating a custom event and dispatching it manually.
B.Attaching a single event listener to a parent element to manage events for its descendants.
C.Using setTimeout to delay an event trigger.
D.Assigning multiple functions to a single event listener.
Correct Answer: Attaching a single event listener to a parent element to manage events for its descendants.
Explanation:Event delegation leverages event bubbling to handle events at a higher level in the DOM (parent) rather than attaching listeners to every single child element, improving memory usage.
Incorrect! Try again.
19In an event handler, what is the difference between event.target and event.currentTarget?
A.target is the element that triggered the event; currentTarget is the element the listener is attached to.
B.target is the element the listener is attached to; currentTarget is the element that triggered the event.
C.target refers to the mouse position; currentTarget refers to the keyboard state.
D.They are always identical.
Correct Answer: target is the element that triggered the event; currentTarget is the element the listener is attached to.
Explanation:During bubbling/delegation, event.target remains the actual element clicked/interacted with, while event.currentTarget is the element whose addEventListener callback is currently running.
Incorrect! Try again.
20To enable an event listener specifically during the capturing phase, what constitutes the third argument in addEventListener?
A.false
B.true or { capture: true }
C."capture"
D.null
Correct Answer: true or { capture: true }
Explanation:Passing true or an options object { capture: true } as the third argument enables the listener for the capturing phase instead of the default bubbling phase.
Incorrect! Try again.
21Which developer tool tab is primarily used to inspect the DOM structure and modify CSS on the fly?
A.Console
B.Sources
C.Elements (or Inspector)
D.Network
Correct Answer: Elements (or Inspector)
Explanation:The Elements panel allows you to view the HTML as a DOM tree and inspect/modify the CSS styles applied to elements.
Incorrect! Try again.
22What keyword can you write in your JavaScript code to automatically pause execution and open the debugger in the browser?
A.pause
B.stop
C.debugger
D.break
Correct Answer: debugger
Explanation:The debugger statement invokes any available debugging functionality, such as setting a breakpoint. If no debugger is available, the statement has no effect.
Incorrect! Try again.
23Which feature in Chrome DevTools helps identifying Layout Shifts (CLS) and rendering performance?
A.Lighthouse / Performance Tab
B.Application Tab
C.Memory Tab
D.Security Tab
Correct Answer: Lighthouse / Performance Tab
Explanation:The Performance tab records runtime performance, and Lighthouse provides audits for Core Web Vitals, including Cumulative Layout Shift (CLS).
Incorrect! Try again.
24In the Network tab of browser DevTools, what does the status code 404 indicate?
A.Server Error
B.Success
C.Not Found
D.Unauthorized
Correct Answer: Not Found
Explanation:HTTP status code 404 indicates that the server cannot find the requested resource.
Incorrect! Try again.
25What is the primary purpose of a Module Bundler like Webpack or Vite?
A.To compile Java code to JavaScript.
B.To combine multiple JavaScript files and dependencies into a single (or few) files for the browser.
C.To run the backend server.
D.To test the database connection.
Correct Answer: To combine multiple JavaScript files and dependencies into a single (or few) files for the browser.
Explanation:Module bundlers take the dependency graph of an application (JS modules, CSS, images) and bundle them into optimized static assets that the browser can load efficiently.
Incorrect! Try again.
26What is 'Tree Shaking' in the context of modern build tools?
A.Randomizing variable names for security.
B.Eliminating dead (unused) code from the final bundle.
C.Reorganizing the folder structure automatically.
D.Splitting the CSS from the JavaScript.
Correct Answer: Eliminating dead (unused) code from the final bundle.
Explanation:Tree shaking is a term used for dead code elimination. It removes code that is imported but never actually used in the application to reduce bundle size.
Incorrect! Try again.
27In Webpack, what is the role of a 'Loader'?
A.It loads the website in the browser.
B.It transforms files other than JavaScript (like CSS, Images, TypeScript) into valid modules.
C.It downloads npm packages.
D.It manages the database connection.
Correct Answer: It transforms files other than JavaScript (like CSS, Images, TypeScript) into valid modules.
Explanation:Loaders allow webpack to process other types of files and convert them into valid modules that can be consumed by your application and added to the dependency graph.
Incorrect! Try again.
28What is 'Minification'?
A.Making the browser window smaller.
B.Removing whitespace, comments, and shortening variable names to reduce file size.
C.Compressing images only.
D.Writing less code manually.
Correct Answer: Removing whitespace, comments, and shortening variable names to reduce file size.
Explanation:Minification is the process of removing unnecessary characters from source code without changing its functionality to improve load times.
Incorrect! Try again.
29Which tool is primarily used for Linting (identifying code quality issues and potential bugs)?
A.Prettier
B.ESLint
C.Webpack
D.Babel
Correct Answer: ESLint
Explanation:ESLint is a static code analysis tool for identifying problematic patterns found in JavaScript code (quality and logical errors).
Incorrect! Try again.
30Which tool is primarily used for Code Formatting (enforcing style consistency like indentation and quotes)?
A.ESLint
B.Prettier
C.Jest
D.PostCSS
Correct Answer: Prettier
Explanation:Prettier is an opinionated code formatter that enforces a consistent style (spacing, commas, quotes) by parsing code and re-printing it.
Incorrect! Try again.
31In a DOM tree, if Node A contains Node B, then:
A.A is a child of B.
B.B is an ancestor of A.
C.B is a descendant of A.
D.A and B are siblings.
Correct Answer: B is a descendant of A.
Explanation:If A contains B, A is the parent (or ancestor) and B is the child (or descendant).
Incorrect! Try again.
32Which method removes a node from the DOM tree in modern browsers?
A.node.delete()
B.node.remove()
C.document.erase(node)
D.node.kill()
Correct Answer: node.remove()
Explanation:The remove() method removes the element from the DOM. The older method was parentNode.removeChild(node).
Incorrect! Try again.
33What happens if you define a script with type="module" in your HTML?
A.It is executed immediately before the DOM is parsed.
B.It is deferred by default and has its own scope (not global).
C.It allows writing PHP inside HTML.
D.It disables all JavaScript features.
Correct Answer: It is deferred by default and has its own scope (not global).
Explanation:ES Modules (type="module") are automatically deferred (executed after HTML parsing) and use strict mode, creating a module scope rather than polluting the global window scope.
Incorrect! Try again.
34What is the concept of 'Hot Module Replacement' (HMR)?
A.Replacing hardware modules while the server is running.
B.Updating modules in the browser at runtime without a full page refresh.
C.Swapping JavaScript for Python.
D.Replacing CSS with SASS.
Correct Answer: Updating modules in the browser at runtime without a full page refresh.
Explanation:HMR exchanges, adds, or removes modules while an application is running, significantly speeding up development by retaining application state.
Incorrect! Try again.
35Using the Console API, which method displays data as an interactive table?
A.console.log()
B.console.table()
C.console.dir()
D.console.list()
Correct Answer: console.table()
Explanation:console.table() displays tabular data as a table, which is very useful for arrays of objects.
Incorrect! Try again.
36If you perform , what allows you to use .forEach?
A.querySelectorAll returns an Array.
B.querySelectorAll returns a NodeList, which supports .forEach in modern browsers.
C.You must convert it to an array first using Array.from.
D.It is a syntax error.
Correct Answer: querySelectorAll returns a NodeList, which supports .forEach in modern browsers.
Explanation:While NodeList is not an Array, modern browsers implement the forEach method on the NodeList prototype.
Incorrect! Try again.
37Which property would you use to change the background color of an element to blue via JavaScript?
Explanation:In JavaScript, CSS properties with hyphens are converted to camelCase. Thus, background-color becomes backgroundColor.
Incorrect! Try again.
38What is the standard configuration file name for ESLint?
A.eslint.config.js
B..eslintrc (or .eslintrc.json/js)
C.lint.config
D.package.json only
Correct Answer: .eslintrc (or .eslintrc.json/js)
Explanation:While newer versions use eslint.config.js, historically and commonly .eslintrc, .eslintrc.json, or .eslintrc.js are the standard configuration files.
Incorrect! Try again.
39To clone a node and all of its descendants (deep copy), how should cloneNode be called?
A.node.cloneNode()
B.node.cloneNode(true)
C.node.cloneNode(false)
D.node.deepClone()
Correct Answer: node.cloneNode(true)
Explanation:Passing true to cloneNode creates a deep clone (includes children). Default (or false) creates a shallow clone (node only).
Incorrect! Try again.
40Which event fires when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets and images?
A.load
B.DOMContentLoaded
C.beforeunload
D.readystatechange
Correct Answer: DOMContentLoaded
Explanation:DOMContentLoaded fires as soon as the HTML is parsed. The load event waits for all external resources (images, css) to finish loading.
Incorrect! Try again.
41In a build pipeline, what is 'Transpilation' (e.g., using Babel)?
A.Converting TypeScript to Java.
B.Converting modern JavaScript (ES6+) into backward-compatible JavaScript (ES5) for older browsers.
C.Compressing image files.
D.Translating comments into another language.
Correct Answer: Converting modern JavaScript (ES6+) into backward-compatible JavaScript (ES5) for older browsers.
Explanation:Transpilers like Babel read source code written in one programming language (or version) and produce the equivalent code in another (usually older version) to ensure compatibility.
Incorrect! Try again.
42What does the command npm run build typically do in a front-end project?
A.Starts a development server.
B.Runs unit tests.
C.Executes the build script defined in package.json to generate production assets.
D.Installs dependencies.
Correct Answer: Executes the build script defined in package.json to generate production assets.
Explanation:npm run build executes the script mapped to "build" in package.json, typically triggering the bundler to create optimized files for deployment.
Incorrect! Try again.
43When debugging, what allows you to execute code in the context of the currently paused function?
A.The Console
B.The Network Tab
C.The Elements Tab
D.The Application Tab
Correct Answer: The Console
Explanation:When the debugger is paused at a breakpoint, the Console has access to the current scope (local variables) of the paused function.
Incorrect! Try again.
44Which DOM property creates a reference to the next node in the same tree level?
A.nextSibling
B.firstChild
C.parentNode
D.childNodes
Correct Answer: nextSibling
Explanation:nextSibling returns the node immediately following the specified one in their parent's childNodes list.
Incorrect! Try again.
45How do you correctly remove an event listener named handleClick?
Explanation:To remove a listener, you must use removeEventListener with the same event type and the exact function reference used in addEventListener.
Incorrect! Try again.
46Which of the following is a benefit of using a 'CSS-in-JS' approach or Dynamic Styling?
A.It reduces the size of HTML files.
B.It allows styles to be scoped to components and change based on application state (variables).
C.It removes the need for a browser.
D.It converts CSS to binary.
Correct Answer: It allows styles to be scoped to components and change based on application state (variables).
Explanation:Dynamic styling allows styles to react to logic (e.g., color: props.active ? 'red' : 'blue') and usually handles scoping automatically.
Incorrect! Try again.
47What creates a 'Memory Leak' regarding event listeners?
A.Adding a listener to a button.
B.Removing an element from the DOM but failing to remove the event listeners attached to it.
C.Using console.log too often.
D.Using querySelector instead of getElementById.
Correct Answer: Removing an element from the DOM but failing to remove the event listeners attached to it.
Explanation:If elements are removed from the DOM but their event listeners (referencing the DOM node) are not removed, the garbage collector may not be able to free the memory.
Incorrect! Try again.
48In the context of linting, what does the --fix flag usually do?
A.It ignores all errors.
B.It automatically corrects fixable errors (like missing semicolons or indentation).
C.It deletes files with errors.
D.It creates a report in PDF format.
Correct Answer: It automatically corrects fixable errors (like missing semicolons or indentation).
Explanation:Running a linter with --fix attempts to automatically resolve simple stylistic or syntax issues without manual intervention.
Incorrect! Try again.
49Which object represents the browser window and serves as the global scope in client-side JavaScript?
A.document
B.root
C.window
D.console
Correct Answer: window
Explanation:The window object represents the browser's window. All global JavaScript objects, functions, and variables automatically become members of the window object.
Incorrect! Try again.
50If you have a list of items <li>, and you want to log the text of the clicked item using Event Delegation on the parent <ul>, which property checks if the clicked target was actually an <li>?
A.event.target.tagName === 'LI'
B.event.target.type === 'LI'
C.event.currentTarget.tagName === 'LI'
D.event.isLi()
Correct Answer: event.target.tagName === 'LI'
Explanation:In delegation, you check event.target.tagName (which returns upper-case tags in HTML) or use event.target.matches('li') to ensure the click happened on the desired child element.