How does the temporal dead zone impact function expressions in JavaScript?

  • It prevents the use of arrow functions in function expressions.
  • It enforces a delay in the execution of function expressions.
  • It causes a runtime error if a variable is accessed before its declaration in a function.
  • It makes function expressions execute before other code in the same scope.
The temporal dead zone (TDZ) is a phase during the variable initialization in JavaScript. It occurs between the variable's declaration and its assignment. During this phase, trying to access the variable will result in a ReferenceError. This impacts function expressions as variables declared within them are also subject to the TDZ. If you try to access such a variable before its declaration, it will lead to a runtime error.

Which method is commonly used to iterate through elements of an array in JavaScript?

  • for...in loop
  • forEach() method
  • while loop
  • map() method
The forEach() method is commonly used to iterate through elements of an array in JavaScript. It allows you to execute a provided function once for each array element, making it a straightforward choice for looping through arrays. The other options, such as for...in loop, while loop, and map() method, have different use cases and are not the most common choices for simple array iteration.

In order to make an object iterable with a for...of loop, you need to define its _______ method.

  • loop
  • forEach
  • Symbol.iterator
  • Object.iterable
To make an object iterable with a for...of loop, you need to define its Symbol.iterator method. This method should return an iterator object, which must have a next method that provides values one at a time. This enables you to use a for...of loop to iterate over the object's elements.

You're developing a game and you're using a two-dimensional array to represent a grid of game cells. How could you access the third cell in the second row of a grid defined as const grid = [[1,2,3], [4,5,6], [7,8,9]]?

  • grid[2][1]
  • grid[1][2]
  • grid[3][2]
  • grid[2][3]
In JavaScript, two-dimensional arrays are accessed using two pairs of square brackets. To access the third cell in the second row, you should use grid[1][2], where the first index (1) represents the second row, and the second index (2) represents the third cell within that row.

How can a "for" loop be used to iterate through the properties of an object?

  • By using for...of loop
  • By using for...in loop
  • By using forEach method
  • By using while loop
To iterate through the properties of an object, you should use a for...in loop. This loop iterates over the enumerable properties of an object and allows you to access each property name (key). The for...of loop is used for iterating over iterable objects like arrays. The forEach method is specifically used for arrays, and while loops are generally used for repetitive tasks with a condition.

To change the content of an HTML element, you can use textContent or _________.

  • innerHTML
  • setAttribute
  • createTextNode
  • appendChild
To change the content of an HTML element using JavaScript, you can use the textContent property. This property sets or returns the text content of an element, allowing you to update the visible text within an HTML element.

To merge two arrays into a single array, you can use the _______ method.

  • merge()
  • concat()
  • join()
  • combine()
The correct method is concat(). The concat() method is used to merge two or more arrays into a single array. It doesn't modify the original arrays but returns a new array containing the elements from the source arrays. For example, const mergedArray = array1.concat(array2); merges array1 and array2 into mergedArray.

document.querySelector('p') will select the _________

element in the HTML document.

  • first
  • last
  • random
  • first matching
document.querySelector('p') will select the first

element in the HTML document that matches the selector. If multiple

elements exist, it selects the first one it encounters in the document's order.

The ________ loop is useful for iterating through the elements of an array.

  • while
  • for
  • do...while
  • forEach
The "for" loop is commonly used for iterating through the elements of an array in JavaScript. It provides more control over the iteration process, allowing you to specify the initialization, condition, and increment, making it suitable for looping through arrays by using the array's length as a condition. The other loop types mentioned are not as commonly used for this purpose.

How can you handle errors with Fetch API in a way that also catches HTTP error statuses?

  • Using try...catch blocks
  • Checking the status property
  • Using the .then() method
  • Using the .error() method
You can handle errors with Fetch API by using try...catch blocks. While the Fetch API does not throw exceptions for HTTP error statuses (e.g., 404 or 500), it does throw exceptions for network errors (e.g., no internet connection). By wrapping your Fetch code in a try...catch block, you can catch both types of errors and handle them appropriately, ensuring a robust error-handling mechanism.