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.

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.

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.

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.

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.

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.

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.

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.

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.

When a function expression is made async, it returns a ______.

  • Promise
  • Callback
  • Generator
  • Class
When a function expression is marked as "async," it returns a Promise. An async function can pause its execution and wait for the Promise to resolve or reject, which is helpful for handling asynchronous operations elegantly.

The _______ pattern is used to create an instance of an object with some default values.

  • Factory
  • Prototype
  • Singleton
  • Observer
The Factory pattern is used to create an instance of an object with some default values. It provides an interface for creating objects in a super factory or a factory method. This pattern is commonly used in JavaScript to create objects.

What is the output of the arithmetic expression 7 / 0 in JavaScript?

  • 0
  • Infinity
  • NaN (Not-a-Number)
  • Error
The output of the arithmetic expression 7 / 0 in JavaScript is Infinity. In JavaScript, dividing a number by 0 results in positive or negative infinity depending on the sign of the numerator. Attempting to divide by 0 does not throw an error, but it produces infinity.