Which of the following options is a technique to manage callback hell in JavaScript?

  • Promises
  • Event emitters
  • Error handling strategies
  • Callback chaining
Promises are a technique in JavaScript to manage callback hell. They provide a more structured and readable way to handle asynchronous operations, allowing you to chain multiple asynchronous calls together, making the code cleaner and easier to understand.

What kind of problem might closures introduce in your code if not used properly?

  • Memory Leaks
  • Faster Execution
  • Enhanced Security
  • Code Optimization
Closures, if not used properly, can introduce memory leaks in your code. When inner functions retain references to variables in the outer function, those variables can't be garbage collected even after they are no longer needed. This can lead to increased memory usage and decreased performance. To avoid memory leaks, it's essential to be mindful of how closures are created and when they are released.

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.

In JavaScript, you can add a new property to an object by simply assigning a value to it with the _________ operator.

  • add
  • extend
  • assign
  • new
In JavaScript, you can add a new property to an object by simply assigning a value to it with the assign operator. The assign operator is used to add or update properties on an object. It's a common operation for dynamically working with objects and their properties in JavaScript.

How do you denote a block of code to be executed if a condition is true?

  • By enclosing it in curly braces {}
  • By using square brackets []
  • By using parentheses ()
  • By using angle brackets <>
In JavaScript, you denote a block of code to be executed if a condition is true by enclosing it in curly braces {}. These braces create a code block that allows you to execute multiple statements when the condition is met.

The _______ method is used to handle errors in Promises.

  • .then()
  • .catch()
  • .resolve()
  • .reject()
The correct method to handle errors in Promises is the .catch() method. When a Promise is rejected, the .catch() method is called with the reason for the rejection, allowing you to handle and manage errors in your asynchronous code effectively.