You're debugging a JavaScript application and notice that a function defined within an object method using an arrow function is not behaving as expected. The "this" keyword is not referring to the object. What could be the reason for this?

  • Arrow functions always bind "this" to the object
  • Arrow functions don't have their own "this"
  • Objects cannot contain arrow functions
  • The object's properties are incorrectly defined
Arrow functions in JavaScript do not have their own "this" context. Instead, they inherit the "this" value from their containing function or the global context. If an arrow function is used inside an object method, it will use the "this" from the surrounding scope, which might not be the object itself.

When using querySelectorAll, the returned object is a _______.

  • NodeList
  • HTMLCollection
  • Array
  • Element
When you use querySelectorAll, it returns a NodeList. A NodeList is a collection of DOM elements that match the specified selector. Unlike an HTMLCollection, a NodeList is not live, which means it won't change dynamically as the document does.

Which part of a "for" loop is executed only once, when the loop starts?

  • Initialization
  • Condition
  • Increment
  • Body of the loop
The part of a "for" loop that is executed only once, when the loop starts, is the initialization. It is where you define and initialize loop control variables. The condition is checked before each iteration, the increment is executed after each iteration, and the body of the loop contains the code that is executed repeatedly until the condition is false.

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.

What is the result of the comparison operator === if the operands are of different types?

  • FALSE
  • TRUE
  • Undefined
  • Error
The comparison operator === (strict equality) in JavaScript returns true if the operands are of different types and have the same value. JavaScript performs type coercion with ==, but === strictly checks both value and type.

What is the time complexity of the unshift() method in JavaScript arrays?

  • O(n)
  • O(1)
  • O(log n)
  • O(n log n)
The unshift() method in JavaScript arrays has a time complexity of O(n), where "n" represents the number of elements in the array. This is because it needs to shift all existing elements to make room for the new element at the beginning. The higher the number of elements, the longer it takes.

Which design pattern can be used to create a family of related or dependent objects without specifying their concrete classes?

  • Factory Method Pattern
  • Abstract Factory Pattern
  • Singleton Pattern
  • Prototype Pattern
The Abstract Factory Pattern allows you to create families of related or dependent objects without specifying their concrete classes. It provides an interface for creating objects in various categories while ensuring their compatibility within the family.

Which statement is true regarding function scope in JavaScript?

  • Functions can access variables from outer scopes.
  • Variables declared inside functions have global scope.
  • Variables declared inside functions have function scope.
  • Variables declared inside functions are accessible only within that function's block.
In JavaScript, variables declared inside functions have function scope, meaning they are only accessible within that function. This is important for encapsulation and avoiding variable conflicts. Variables declared outside of functions have global scope, and functions can access variables from outer scopes, but the reverse is not true.

The _________ event does not necessarily have to be attached to a form element.

  • submit
  • reset
  • change
  • keydown
The change event in JavaScript doesn't necessarily have to be attached to a form element. It can also be used with other HTML elements like ,