To remove a child element, you should use the removeChild method on the _________ element.

  • parent
  • child
  • document
  • sibling
To remove a child element from the DOM using JavaScript, you should use the removeChild method on the parent element that contains the child you want to remove. The removeChild method doesn't directly operate on the child element itself.

The _______ pattern allows a new object to be created by cloning an existing object to avoid the overhead of creating an object from scratch.

  • Singleton
  • Prototype
  • Decorator
  • Observer
The Prototype pattern allows a new object to be created by cloning an existing object, avoiding the overhead of creating an object from scratch. It involves creating an object as a prototype and then creating new instances by copying that prototype.

Given the short-circuiting nature of logical operators in JavaScript, what will be the output of the expression false && someUndeclaredVariable?

  • FALSE
  • TRUE
  • Throws an error
  • undefined
JavaScript's logical operators like && and

How does the await keyword manage the Promise’s resolve value?

  • It changes the resolve value to a boolean.
  • It extracts the resolve value from the Promise.
  • It modifies the Promise's behavior.
  • It cancels the Promise.
The 'await' keyword is used in async functions to pause the execution until the Promise is resolved. When the Promise resolves, the 'await' expression returns the resolved value. It doesn't change the value to a boolean or modify the Promise itself. This behavior is crucial for handling asynchronous operations more effectively.

You are tasked with refactoring a piece of legacy code where a function declaration within a conditional block is causing inconsistent behavior across different JavaScript engines. What is a potential solution to ensure consistent behavior?

  • Use a function expression instead of a declaration within the conditional block.
  • Ensure the function is declared with the 'let' keyword.
  • Wrap the function declaration in a try-catch block to handle any errors.
  • Split the code into multiple conditional blocks.
To ensure consistent behavior across different JavaScript engines, it's advisable to use a function expression within a conditional block instead of a function declaration. Function declarations are hoisted to the top of their containing function or script, which may lead to inconsistent results in legacy code.

In JavaScript, the "this" keyword inside an arrow function is defined by its _________ context.

  • Global
  • Lexical
  • Local
  • Execution
In JavaScript, the "this" keyword inside an arrow function is defined by its lexical context. Unlike regular functions, arrow functions do not have their own "this" binding, so they inherit the "this" value from the surrounding code block, which is determined by the lexical scope.

A callback function is passed as an ________ to other functions and is executed after its parent function has completed.

  • argument
  • object
  • attribute
  • expression
A callback function is passed as an "argument" to other functions in JavaScript. It is a function that is executed after its parent function has completed its execution. This allows for asynchronous operations and event handling in JavaScript.

Which method returns a promise that resolves with the result of parsing the body text as JSON?

  • .json() method
  • .text() method
  • .body() method
  • .parseJSON() method
The .json() method of a Response object returned by fetch parses the response body text as JSON and returns a Promise that resolves with the parsed data. This method is commonly used when making API requests to obtain structured data in JSON format. The .text() method returns the response body as plain text, while .body() does not exist, and .parseJSON() is not a standard method in JavaScript.

The createElement method is used to create a new element in the _________.

  • browser
  • JavaScript
  • document
  • DOM
The createElement method in JavaScript is used to create a new HTML element within the Document Object Model (DOM). It allows you to dynamically create HTML elements that can be added to the web page or modified as needed.

How can one emulate the functionality of a switch statement using objects and functions in JavaScript?

  • By creating an object where each property maps to a case label, and the corresponding values are functions to execute.
  • By using a for loop to iterate through cases and execute corresponding functions.
  • By using the "continue" keyword in a loop to simulate case behavior.
  • By creating an array of functions, where each function corresponds to a case label.
To emulate the functionality of a switch statement in JavaScript, you can create an object where each property represents a case label, and the corresponding property values are functions that perform the desired actions. You can then use the input value to access the appropriate function from the object, effectively simulating switch behavior.