The method _______ returns the index of the first element in the array that satisfies the provided testing function.

  • findIndex()
  • indexOf()
  • search()
  • locateIndex()
The findIndex() method is used to find the index of the first element in an array that satisfies a provided testing function. It iterates through the array, executing the function for each element until a match is found or it reaches the end of the array.

What does the pop() method do to a JavaScript array?

  • Removes the last element
  • Removes the first element
  • Adds an element to the end
  • Adds an element to the beginning
The pop() method in JavaScript removes the last element from an array and returns that element. This operation reduces the length of the array by 1. It's the opposite of the push() method, which adds an element to the end of the array. pop() is useful for removing elements from the end of a stack-like structure.

A do-while loop is particularly useful when you want to ensure the loop body executes at least ________ before checking the condition.

  • Once
  • Twice
  • Never
  • Once or more
A do-while loop is useful when you want to guarantee that the loop body executes at least "once" before checking the condition. This is because in a do-while loop, the condition is evaluated after the loop body, ensuring that the code inside the loop executes at least once, even if the condition is initially false.

You're troubleshooting a web application and notice that an event is not being captured during the capturing phase as expected. What could be a potential reason for this event not being captured?

  • The event is not properly attached
  • The event is not registered
  • The event is being canceled by another event
  • The event handler is asynchronous
One potential reason for an event not being captured during the capturing phase is that the event is not properly attached to the target element. Capturing phase events need to be registered correctly using methods like addEventListener with the true parameter to enable the capturing phase. Other options may affect event handling but are not specific to the capturing phase.

To avoid cross-site scripting (XSS) attacks, instead of innerHTML, use _________.

  • textContent
  • appendChild
  • createElement
  • setAttribute
To prevent XSS attacks, it's recommended to use the textContent property. Unlike innerHTML, which can execute scripts, textContent only sets the text content of an element, making it safer for user-generated input.

The method _________ is used to parse a JSON response in Fetch API.

  • .json()
  • .parseJSON()
  • .stringify()
  • .fromJSON()
In the Fetch API, the .json() method is used to parse a JSON response. It takes the JSON response and returns a JavaScript object that you can work with in your code, making it easier to extract and use the data.

What is the primary difference between a class and an instance?

  • A class is a blueprint for objects
  • An instance is a prototype for classes
  • A class is an object
  • An instance is a collection of methods
The primary difference between a class and an instance in JavaScript is that a class serves as a blueprint or template for creating objects, while an instance is a specific object created from that class. Classes define the structure and behavior of objects, while instances are actual objects with their unique data and state.

A common use-case for a "for" loop in asynchronous programming is to use it with the ________ function.

  • setTimeout
  • setInterval
  • async/await
  • Promise
A common use-case for a "for" loop in asynchronous programming is to use it with the Promise function. Promises are often used to handle asynchronous operations in JavaScript, allowing you to work with asynchronous data in a more structured manner, making it a crucial part of modern JavaScript development.

The Fetch API returns a _________ which resolves to the Response of the request, whether it is successful or not.

  • Promise
  • Callback
  • Array
  • Event
The Fetch API returns a Promise, which allows you to handle asynchronous operations. This Promise resolves to the Response object of the request, containing information about the request and its status, whether it succeeds or not.

Which method is used to attach an event listener to an element in JavaScript?

  • addListener()
  • addEventListener()
  • attachEvent()
  • addEventHandler()
In JavaScript, the correct method to attach an event listener to an element is addEventListener(). This method allows you to specify the event type to listen for and the function to execute when the event occurs. It is the modern and recommended way to handle events in JavaScript.