When using a for...of loop with strings, each iteration will provide a single _______.

  • Character
  • Word
  • Line
  • Number
When using a for...of loop with strings, each iteration will provide a single character. This loop is useful for breaking down strings into individual characters for various processing tasks, such as counting characters or manipulating them individually.

The switch statement evaluates expressions based on their _________.

  • Values
  • Cases
  • Conditions
  • Labels
The switch statement in JavaScript evaluates expressions based on their cases. Each case represents a possible value that the expression can take, and the code block associated with the matching case is executed. This allows for multiple execution paths based on different values of the expression.

In JavaScript, the _______ method is used to create a new object using an existing object as the prototype of the newly created object.

  • Object.create()
  • Object.assign()
  • Object.extend()
  • Object.instantiate()
In JavaScript, the Object.create() method is used to create a new object with the specified prototype object. It allows you to create objects that inherit properties and methods from an existing object, making it a powerful tool for prototypal inheritance.

In JavaScript, the ________ function is often used for delaying the execution of a function in an asynchronous manner.

  • setTimeout
  • setInterval
  • asyncWait
  • delayFunction
In JavaScript, the setTimeout function is often used for delaying the execution of a function in an asynchronous manner. It schedules the execution of a function after a specified time delay, allowing for tasks like animations or asynchronous operations to be handled.

Which array method adds elements to the beginning of an array?

  • push()
  • unshift()
  • concat()
  • splice()
The unshift() method is used to add elements to the beginning of an array. It's particularly useful when you want to insert one or more elements at the start of an existing array without affecting the order of the existing elements. Unlike push(), which adds elements to the end, unshift() works at the beginning.

What is a closure in JavaScript?

  • A secure way to store passwords
  • A private function
  • A way to handle exceptions
  • A function that remembers its lexical scope
A closure in JavaScript is a function that "remembers" its lexical scope, even when it's executed outside that scope. This allows the function to maintain access to variables from its parent scope, creating a powerful mechanism for encapsulation and data privacy.

In which context does the "this" keyword not refer to the object that calls the function?

  • Global context
  • Method context
  • Function context
  • Constructor context
The "this" keyword in JavaScript does not refer to the object that calls the function in the global context. In the global context, "this" points to the global object, which is usually the "window" object in browsers. This can be a source of confusion, so it's essential to understand the various contexts in which "this" behaves differently.

Why might recursive function expressions cause issues in certain scenarios?

  • They can cause an infinite loop and lead to a stack overflow error.
  • They can only be used for mathematical calculations and not for general-purpose recursion.
  • They can't access variables from the outer scope.
  • They are less efficient than iterative approaches.
Recursive function expressions, if not designed carefully, can cause infinite recursion, which leads to a stack overflow error. Each recursive call adds a new function call to the stack, and if there's no base case to stop the recursion, it will continue indefinitely. It's essential to have a termination condition to prevent such issues.

To handle both resolve and reject in a single method, you can use the .finally method after a(n) _______ block in asynchronous functions.

  • try
  • await
  • then
  • catch
To handle both resolve and reject outcomes in a single method, you can use the .finally() method after a try block in asynchronous functions. This ensures that the provided code block is executed regardless of whether the Promise is resolved or rejected.

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

  • shift()
  • pop()
  • unshift()
  • splice()
The pop() method in JavaScript is used to remove the last element from an array and return that element. This is commonly used for tasks like removing the last item from a stack implemented as an array. shift() removes the first element, unshift() adds elements to the beginning, and splice() is used for more complex array manipulation.

The ______ operator is used to check both value and type.

  • ==
  • ===
  • =
  • !==
The === operator in JavaScript is used for strict equality comparison. It checks both the value and the type of the operands. It returns true if both the value and the type are the same, and false otherwise. Understanding strict equality is crucial to prevent unexpected type coercion bugs.

What will be the return value of ["apple", "banana", "cherry"].pop();?

  • "apple"
  • "banana"
  • "cherry"
  • undefined
The return value will be "cherry". The pop() method removes the last element from an array and returns that element. In this case, it removes "cherry" from the end of the array and returns it.