Which keyword is used to stop the loop prematurely?

  • break
  • continue
  • exit
  • return
The keyword used to stop a loop prematurely in JavaScript is "break." When "break" is encountered within a loop, it immediately exits the loop, even if the loop condition is still true or there are more iterations remaining. This is useful for early termination of a loop based on a specific condition. "continue" skips the current iteration and moves to the next one, while "exit" and "return" have different purposes and are not used for loop control.

In a while loop, forgetting to update the condition can lead to a/an ________ loop.

  • Infinite
  • Endless
  • Eternal
  • Unstoppable
In a while loop, if you forget to update the condition, it can lead to an "infinite" loop, where the loop continues to execute indefinitely. This can cause the program to hang or become unresponsive. It's important to ensure that the loop's condition is updated to eventually become false.

In a performance-critical application, minimizing the reshuffling of array elements is vital. What method might be avoided when removing elements due to its time complexity?

  • splice()
  • push()
  • pop()
  • shift()
The splice() method should be avoided when removing elements from an array in a performance-critical application because it has a time complexity of O(n) due to the need to shift elements after the removal. Methods like pop() (O(1)), shift() (O(1)), or slice() (O(n)) may be more appropriate.

You've encountered a bug in your JavaScript code where a variable is not retaining an expected value within a nested function. What feature of JavaScript should you explore to troubleshoot this issue?

  • Lexical Scoping
  • Hoisting
  • IIFE (Immediately Invoked Function Expression)
  • Event Delegation
To troubleshoot the issue of a variable not retaining an expected value within a nested function, you should explore the concept of lexical scoping. Lexical scoping (also known as static scoping) means that the scope of a variable is determined by its location within the source code, and nested functions have access to variables from their containing (parent) functions. This understanding will help you identify and fix the problem.

How can one implement a switch statement to handle multiple data types efficiently?

  • By using the "case" keyword for each data type and applying type conversion in each case.
  • By using the "default" keyword to handle unexpected data types.
  • By wrapping the switch statement in a try-catch block for error handling.
  • By using an array of functions, where each function handles a specific data type.
To handle multiple data types efficiently in a switch statement, you can create an array of functions, where each function corresponds to a specific data type. When you receive input, you can then call the appropriate function based on the data type, which offers more flexibility and avoids type conversion complexities.

Which property of the Response object represents the status text of the response?

  • statusText
  • statusCode
  • status
  • statusDescription
The statusText property of the Response object represents the status text of the HTTP response. It provides a textual description of the HTTP status code, such as "OK" for status code 200 or "Not Found" for status code 404. This property is useful for understanding the meaning of the response status code in a more human-readable form.

When dealing with callbacks, the first argument is traditionally

  • Callback
  • Error
  • Function
  • Result
When dealing with callbacks, the first argument is traditionally reserved for Error. This convention allows developers to handle errors gracefully when executing asynchronous operations. It helps in proper error handling and prevents unexpected crashes in your code.

What is the purpose of the status property in an HTTP response?

  • To specify the content type
  • To indicate the HTTP status
  • To define the response data
  • To specify the request method
The status property in an HTTP response is used to indicate the HTTP status code for the response. HTTP status codes provide information about the outcome of an HTTP request, such as whether it was successful (e.g., status code 200 for OK) or encountered an error (e.g., status code 404 for Not Found). It helps the client understand the result of the request.

While reading through a JavaScript codebase, you see a function that is returned from another function and retains access to its lexical scope, even after the outer function has finished execution. What is this pattern called?

  • Callback
  • Promise
  • IIFE (Immediately Invoked Function Expression)
  • Higher-order Function
This pattern is known as a "Higher-order Function." In JavaScript, higher-order functions are functions that can take other functions as arguments or return them. This enables functions to maintain access to their lexical scope, creating closures.

Which of the following JavaScript methods can create a new HTML element?

  • createElement()
  • createNode()
  • createTag()
  • newElement()
You can create a new HTML element in JavaScript using the createElement() method. This method is used to dynamically generate HTML elements in your code. It takes the name of the HTML tag you want to create as an argument.

The arithmetic operator _______ increments the value of a variable by 1.

  • ++
  • --
  • +
  • +=
The arithmetic operator '++' is known as the increment operator. It increases the value of a variable by 1. For example, if you have a variable x and you write x++, it will increment the value of x by 1. This is commonly used in loops and counters in JavaScript.

You're refactoring your code to improve performance and notice a function that returns another function, accessing variables outside of its own scope. What specific JavaScript concept should you consider when optimizing this code section?

  • Function Closures
  • Function Prototypes
  • Event Bubbling
  • AJAX (Asynchronous JavaScript and XML)
When optimizing code that returns a function and accesses variables outside of its own scope, you should consider the concept of function closures. Function closures allow an inner function to "remember" and access variables from its containing (parent) function's scope even after the parent function has finished executing. This can be useful for encapsulating state and optimizing code.