How do you define a property inside a JavaScript object?

  • Using dot notation
  • Using square brackets
  • Using a constructor function
  • Using the prototype keyword
You can define a property inside a JavaScript object using dot notation, where you specify the object name followed by a dot and then the property name. For example: objectName.propertyName. This is the most common way to define object properties.

Using a switch statement with a very large number of cases might affect the _________.

  • Code Readability
  • Performance
  • Variable Scope
  • Error Handling
Using a switch statement with a very large number of cases might affect the performance of your JavaScript code. The larger the number of cases, the longer it may take to find a matching case, impacting the execution speed of your code. It's important to consider this when using switch statements in performance-critical code.

Which of the following methods can select multiple elements?

  • querySelector
  • getElementByClass
  • getElementByTag
  • querySelectorAll
The querySelectorAll method can select multiple elements that match a specified CSS selector. It returns a NodeList containing all matching elements. The other options select only single elements.

What is the index of the last element of an array with 5 elements?

  • 3
  • 4
  • 5
  • -1 (JavaScript doesn't support accessing the last element directly)
The index of the last element in an array with 5 elements is 4. JavaScript arrays are zero-indexed, so the index of the last element is one less than the total number of elements in the array. The other options are not correct for this scenario.

The fetch function in JavaScript returns a Promise that resolves to the ________ of the request, whether it is successful or not.

  • a) Response Object
  • b) JSON Data
  • c) Status Code
  • d) URL
The fetch function in JavaScript returns a Promise that resolves to the Response object of the request, whether it's successful or not. This Response object contains information about the response, including headers and the response body, and allows you to handle the response appropriately.

You are troubleshooting an issue where the Fetch API call to a third-party API is not returning any data, and you suspect it might be due to a CORS policy. How might you validate and debug this issue?

  • Use a CORS proxy
  • Check the browser console
  • Modify the server's CORS policy
  • Reboot the server
To validate and debug a CORS (Cross-Origin Resource Sharing) issue, you can check the browser console for error messages, which often provide information about the CORS policy violation. Modifying the server's CORS policy or using a CORS proxy can help resolve such issues. Rebooting the server is unlikely to fix CORS problems.

What will be the output of console.log(typeof null); in JavaScript?

  • "object"
  • "null"
  • "undefined"
  • "number"
The expression console.log(typeof null); in JavaScript will output "object." This is a quirk in JavaScript because typeof null returns "object," even though null is not an object but a special value representing the absence of a value.

In which scenario might you prefer to use Object.create(null) over {} to create an empty object?

  • When you need an empty object with no prototype chain (no inherited properties or methods)
  • When you need an empty object with default prototype properties
  • When you need an object with prototype properties
  • When you need an object with getter and setter methods
Object.create(null) is used when you want an empty object with no prototype chain. This is useful when you want to create a clean slate object without inheriting any properties or methods from the Object prototype.

The insertBefore method is used to insert an element before the _________ child of a specified parent.

  • first
  • last
  • next
  • previous
The insertBefore method is used to insert an element before the specified next child of a parent element. It allows you to precisely control the position of the new element within the parent's children.

How do you select the last child of an element using pure JavaScript?

  • lastChild
  • element.lastChild
  • lastElementChild
  • element.lastElementChild
To select the last child of an element using pure JavaScript, you should use the lastElementChild property of the element. This property returns the last element among the child elements of the specified parent element. The other options, lastChild, element.lastChild, and lastElementChild, do not provide the same functionality.