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.

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.

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.

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.

Imagine you are implementing a feature to upload a file to the server. Which HTTP method would be most appropriate to use with the Fetch API for this purpose?

  • GET
  • POST
  • PUT
  • DELETE
To upload a file to the server, you would use the POST HTTP method with the Fetch API. The POST method is used for submitting data to be processed to a specified resource, which is suitable for file uploads. GET, PUT, and DELETE have different purposes.

How to declare a constant array in JavaScript?

  • const arr = [];
  • const arr = new Array();
  • const arr = {}
  • const arr = [1, 2, 3];
To declare a constant array in JavaScript, you can use the const keyword followed by square brackets, like const arr = [];. The const keyword ensures that the variable arr cannot be reassigned, making it a constant array.

You are debugging a web page and find that an element isn't being selected as expected with document.querySelector('.example'). What could be a possible reason if the class name is correct?

  • Element not present in the DOM
  • Element is inside an iframe
  • JavaScript not loaded before the query
  • Class name contains special characters or spaces
If an element with the correct class name isn't being selected with document.querySelector('.example'), a possible reason could be that the element is not present in the DOM at the time of the query. Ensure that the element you are trying to select exists and is rendered when your JavaScript runs. The other options are less likely causes.

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.

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.

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.