During a code review, you spot the splice() method being used to remove an element from the end of an array. What alternative method might you suggest for removing elements from the end of an array that might be more performant and simpler?

  • pop()
  • shift()
  • slice()
  • push()
To remove an element from the end of an array, it's more efficient and simpler to use the pop() method. The pop() method removes the last element from the array and returns it, ensuring O(1) time complexity, whereas splice() is unnecessary for this task and can be less efficient.

What is a key difference between arrow functions and regular functions in JavaScript?

  • Arrow functions have their own 'this' context
  • Regular functions are more concise
  • Arrow functions cannot have parameters
  • Regular functions do not allow for anonymous functions
One significant difference between arrow functions and regular functions is that arrow functions do not have their own 'this' context; instead, they inherit 'this' from the surrounding code. Regular functions, on the other hand, have their own 'this' context, which can vary depending on how the function is called.

Which of the following methods mutates the original array?

  • map()
  • filter()
  • concat()
  • reduce()
The concat() method is used to concatenate two or more arrays and returns a new array. It does not mutate the original array. In contrast, methods like map(), filter(), and reduce() can modify the original array, so they should be used with caution.

Which type of event listener will not get removed by the removeEventListener method?

  • Inline event listeners
  • Anonymous event listeners
  • Named function event listeners
  • Arrow function event listeners
Event listeners added using named functions can be removed with the removeEventListener method because they are given a reference to the function. In contrast, inline event listeners, anonymous functions, and arrow functions are not easily removed because they lack a reference. This makes them more challenging to manage and clean up in your code.

How do you declare a variable x and assign it the value 5 in JavaScript?

  • var x = 5;
  • variable x = 5;
  • x = 5;
  • let x = 5;
To declare a variable x and assign it the value 5 in JavaScript, you use the syntax var x = 5;. This initializes the variable x with the value 5. You can also use let or const instead of var for variable declaration.

What is the potential issue with using a for...in loop to iterate over arrays?

  • It throws an error.
  • It iterates only over values.
  • It may include inherited properties.
  • It can't be used with arrays.
Using a for...in loop to iterate over arrays can lead to a potential issue because it not only iterates over the array's own properties but also includes properties that may be inherited from the prototype chain. This can result in unexpected behavior if you're not careful. To avoid this issue, it's recommended to use for...of loops when iterating over arrays or other iterable objects, as they are designed specifically for this purpose and only iterate over the values of the iterable.

What is the primary role of the setTimeout function in asynchronous JavaScript?

  • Delaying code execution
  • Executing code repeatedly
  • Scheduling tasks
  • Controlling the event loop
The primary role of the setTimeout function is to delay the execution of a piece of code for a specified amount of time (in milliseconds). It allows you to schedule a function to run after a specified delay, making it useful for creating timeouts and delays in asynchronous code.

What does the term "scope" refer to in JavaScript?

  • The physical size of a webpage
  • The lifetime of a variable
  • The visibility of a variable
  • The security of a webpage
In JavaScript, "scope" refers to the visibility or accessibility of a variable within a specific part of your code. It determines where in your code a particular variable can be used, which helps prevent naming conflicts and maintain code organization.

Which array method removes the first element from an array and returns that removed element?

  • shift()
  • unshift()
  • pop()
  • push()
The array method that removes the first element from an array and returns that removed element is shift(). It shifts all other elements to a lower index, effectively removing the first element. The unshift() method adds elements to the beginning, pop() removes the last element, and push() adds elements to the end of the array.

The problem of multiple nested callbacks in JavaScript is commonly referred to as ________.

  • callback hell
  • nested loop
  • async overload
  • function maze
The problem of multiple nested callbacks in JavaScript is commonly referred to as "callback hell." It occurs when callback functions are heavily nested, making the code hard to read and maintain. This can lead to readability and maintenance issues.