What is "explicit binding" in JavaScript with regard to the "this" keyword?
- Explicit binding refers to manually setting the "this" value for a function using methods like .bind(), .call(), or .apply().
- Explicit binding is when "this" is automatically determined by the JavaScript engine.
- Explicit binding involves using the "this" keyword without any special methods.
- Explicit binding is only applicable to arrow functions.
In JavaScript, "explicit binding" refers to the manual setting of the "this" value for a function. This is done using methods like .bind(), .call(), or .apply(), allowing you to explicitly specify the object that should be treated as "this" within the function. This is especially useful in cases where the default "this" behavior is not what you need.
What does the responseType property of an XMLHttpRequest object determine?
- The data type of the request
- The request method
- The URL of the request
- The timeout for the request
The responseType property of an XMLHttpRequest object determines the expected data type of the response. It allows you to specify whether you expect the response to be in text, JSON, XML, or other formats. Setting this property correctly is important for parsing and handling the response data properly in your JavaScript code.
In JavaScript, instances are typically created using the _________ keyword.
- class
- new
- instance
- create
In JavaScript, instances of objects are typically created using the new keyword. For example, you can create a new instance of a constructor function using new ConstructorName(). This keyword is essential for creating object instances.
Which of the following is NOT a type of polymorphism supported by JavaScript?
- Compile-time polymorphism
- Runtime polymorphism
- Ad-hoc polymorphism
- Parametric polymorphism
JavaScript supports runtime polymorphism and ad-hoc polymorphism (also known as function overloading), allowing different behavior for functions with the same name but different parameters. Parametric polymorphism is associated with generics and is not a form of polymorphism in JavaScript.
The _________ property of the XMLHttpRequest object holds the status of the XMLHttpRequest.
- statusText
- response
- status
- readyState
The status property of the XMLHttpRequest object holds the HTTP status code of the response received from the server. It indicates whether the request was successful or encountered an error. statusText contains the status message associated with the status code. response contains the response data.
How do you declare a two-dimensional array in JavaScript?
- let arr = [[]];
- let arr = [][[]];
- let arr = [[], []];
- let arr = [[],] [[]];
In JavaScript, a two-dimensional array is declared by creating an array where each element is another array. This creates a matrix-like structure. For example, let arr = [[], []]; declares a 2x2 two-dimensional array. The other options contain syntax errors or do not create a valid two-dimensional array.
In order to create a private variable in JavaScript, you might utilize a ________.
- Closure
- Prototype
- Constructor
- Module
In order to create a private variable in JavaScript, you might utilize a "Module." A module is a design pattern that allows you to encapsulate data and functions, providing a way to create private variables and methods. This helps in achieving data encapsulation and preventing unwanted external access.
What does the prototype property of a function allow you to do?
- a) Create a new instance of the function.
- b) Add new properties and methods to all instances created by that function.
- c) Access the parent prototype of the function.
- d) Change the function's name and scope.
The prototype property of a function in JavaScript allows you to add new properties and methods to all instances created by that function. This is useful for implementing inheritance and sharing common behavior among objects created from the same constructor function. It doesn't create new instances or change the function's name or scope.
You are working with a NodeList after querying the DOM and want to iterate over each node. Which loop would be directly usable without converting the NodeList to an array?
- for...in loop
- for...of loop
- while loop
- NodeList.prototype.forEach() method
The NodeList is not an array, but you can use the NodeList.prototype.forEach() method directly to iterate over its nodes without converting it to an array. It provides a convenient way to work with NodeLists, making it the suitable choice.
The method _______ returns the index of the first element in the array that satisfies the provided testing function.
- findIndex()
- indexOf()
- search()
- locateIndex()
The findIndex() method is used to find the index of the first element in an array that satisfies a provided testing function. It iterates through the array, executing the function for each element until a match is found or it reaches the end of the array.