You are working on a form validation feature where you want to select all input elements within a form. Which method allows you to select all input elements within a specific form element?

  • querySelectorAll('input')
  • getElementById('form')
  • getElementsByTag('form')
  • querySelectorAll('form input')
To select all input elements within a specific form, you should use the querySelectorAll('form input') method. This allows you to target input elements that are descendants of a specific form element. The other options are incorrect because they either select all input elements on the page or attempt to select a form element by ID or tag name, which doesn't filter the input elements within it.

What value types can be used for case comparisons in a switch statement?

  • Strings, numbers, and symbols
  • Arrays, objects, and booleans
  • Only numbers and booleans
  • Functions and undefined values
In a switch statement, you can use strings, numbers, and symbols as values for case comparisons. These values are compared strictly, meaning both value and type must match for the associated code block to execute.

The method _______ can be used to add new elements to the end of an array.

  • push()
  • unshift()
  • add()
  • append()
The push() method in JavaScript can be used to add new elements to the end of an array. This method modifies the original array and is commonly used when you want to add elements to the end of an array, expanding its length. For example, myArray.push('newElement') would add 'newElement' to the end of myArray.

To prevent variables from being added to the global object, it is common to use a(n) _______ function expression.

  • IIFE (Immediately Invoked Function Expression)
  • Arrow
  • Anonymous
  • Prototype
To prevent variables from polluting the global object, an IIFE (Immediately Invoked Function Expression) is commonly used. It encapsulates code within a function scope and immediately executes it, keeping variables private and not accessible from the global scope.

What is a property in JavaScript objects?

  • A value associated with an element in an array
  • A key-value pair associated with an object
  • A function that performs an action
  • A variable declaration
A property in JavaScript objects is a key-value pair associated with an object. The key is a string (or Symbol), and the value can be of any data type. Properties allow you to store data and functions within an object, making it a fundamental concept in JavaScript's object-oriented programming.

Which property is used to change the text content of a selected element?

  • innerText
  • textContent
  • innerHTML
  • text
The textContent property is used to change the text content of a selected element. It sets or returns the text content of an element and ensures that any HTML tags are treated as plain text. The other options do not handle text content in the same way.

Can arrow functions be used as constructors?

  • No
  • Yes
  • Only in ES6
  • Only in ES5
No, arrow functions cannot be used as constructors in JavaScript. Unlike regular functions, arrow functions do not have their own 'this' binding, and they cannot be used with the 'new' keyword to create instances of objects. Arrow functions are primarily used for creating concise function expressions.

To iterate over the entries of an object (key-value pairs), the object should be converted to an array of arrays using Object._______.

  • entries
  • toArray
  • keys
  • values
To iterate over the entries (key-value pairs) of an object, the object should be converted to an array of arrays using Object.entries. This method returns an array containing arrays, each with two elements: the key and its corresponding value from the object. You can then iterate over these pairs.

Which method is commonly used to iterate through elements of an array in JavaScript?

  • for...in loop
  • forEach() method
  • while loop
  • map() method
The forEach() method is commonly used to iterate through elements of an array in JavaScript. It allows you to execute a provided function once for each array element, making it a straightforward choice for looping through arrays. The other options, such as for...in loop, while loop, and map() method, have different use cases and are not the most common choices for simple array iteration.

How does the temporal dead zone impact function expressions in JavaScript?

  • It prevents the use of arrow functions in function expressions.
  • It enforces a delay in the execution of function expressions.
  • It causes a runtime error if a variable is accessed before its declaration in a function.
  • It makes function expressions execute before other code in the same scope.
The temporal dead zone (TDZ) is a phase during the variable initialization in JavaScript. It occurs between the variable's declaration and its assignment. During this phase, trying to access the variable will result in a ReferenceError. This impacts function expressions as variables declared within them are also subject to the TDZ. If you try to access such a variable before its declaration, it will lead to a runtime error.

You're debugging a piece of code and find an unexpected type coercion in a comparison. Which operator is most likely being used that could cause this issue?

  • == (Equality)
  • === (Strict Equality)
  • > (Greater Than)
  • != (Inequality)
The double equal operator (==) performs type coercion during comparison, which means it converts the operands to the same type before comparing. This can lead to unexpected results when comparing values of different types, potentially causing type coercion issues in your code. You should generally prefer strict equality (===) to avoid type coercion.

The ________ interface provides methods to deal with HTTP responses represented in binary format.

  • a) TextDecoder Interface
  • b) FormData Interface
  • c) Blob Interface
  • d) ArrayBuffer Interface
The Blob interface provides methods to deal with HTTP responses represented in binary format. It allows you to work with binary data such as images, audio, or other binary content in a more efficient way. This is essential when handling binary data in web applications.