You are working with a NodeList after querying the DOM and want to iterate over each node. Which loop would be directly usable without converting the NodeList to an array?

  • for...in loop
  • for...of loop
  • while loop
  • NodeList.prototype.forEach() method
The NodeList is not an array, but you can use the NodeList.prototype.forEach() method directly to iterate over its nodes without converting it to an array. It provides a convenient way to work with NodeLists, making it the suitable choice.

What does the prototype property of a function allow you to do?

  • a) Create a new instance of the function.
  • b) Add new properties and methods to all instances created by that function.
  • c) Access the parent prototype of the function.
  • d) Change the function's name and scope.
The prototype property of a function in JavaScript allows you to add new properties and methods to all instances created by that function. This is useful for implementing inheritance and sharing common behavior among objects created from the same constructor function. It doesn't create new instances or change the function's name or scope.

In order to create a private variable in JavaScript, you might utilize a ________.

  • Closure
  • Prototype
  • Constructor
  • Module
In order to create a private variable in JavaScript, you might utilize a "Module." A module is a design pattern that allows you to encapsulate data and functions, providing a way to create private variables and methods. This helps in achieving data encapsulation and preventing unwanted external access.

JavaScript was introduced to the world in the year _________.

  • 1995
  • 2000
  • 1998
  • 1993
JavaScript was introduced to the world in the year 1995. It was first released by Netscape as part of their Navigator 2.0 web browser. JavaScript quickly gained popularity as a client-side scripting language for web development.

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.

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.