A _______ function is a function that accepts up to three arguments: the value of the element, the index of the element, and the array object being traversed.
- callback
- handler
- middleware
- delegate
In JavaScript, a callback function is a function that can be passed as an argument to another function. Callback functions can accept up to three arguments: the value of the element, the index of the element, and the array object being traversed. They are commonly used in asynchronous programming and array methods.
Considering browser compatibility, which array method would you avoid in Internet Explorer 8?
- forEach()
- map()
- filter()
- indexOf()
In terms of browser compatibility, the forEach() method should be avoided in Internet Explorer 8. This method was introduced in ECMAScript 5, and Internet Explorer 8 only supports ECMAScript 3. Other methods like map(), filter(), and indexOf() have more widespread support in older browsers.
The HTTP status code ________ indicates that the request has succeeded.
- 200 OK
- 204 No Content
- 404 Not Found
- 500 Internal Server Error
The HTTP status code 200 OK indicates that the request has succeeded. It is the standard response for successful HTTP requests. The other options represent different HTTP status codes with different meanings, such as 'No Content,' 'Not Found,' and 'Internal Server Error.'
Consider a function that fetches user information from an API. If the API call fails, you want to log an error message and then continue the execution of the function without throwing an exception to the outer scope. Which Promise method should you use to achieve this?
- Promise.catch()
- Promise.finally()
- Promise.reject()
- Promise.resolve()
You should use Promise.catch() to handle errors in a Promise. This method allows you to specify a callback function that will be called when the Promise is rejected, allowing you to log an error message and gracefully continue execution without propagating the error to the outer scope.
You need to filter out the prototype properties while using a loop to iterate over object properties. Which loop would you use, and what additional method would be needed to avoid iterating over prototype properties?
- for...in loop with hasOwnProperty()
- for...of loop with Object.keys()
- while loop with Object.getOwnPropertyNames()
- forEach() method with Object.getOwnPropertyNames()
You would use a for...of loop with Object.keys() to iterate over object properties while excluding prototype properties. Object.keys() returns an array of an object's own enumerable property names, ensuring that prototype properties are filtered out.
Why does 0.1 + 0.2 !== 0.3 in JavaScript?
- JavaScript has floating-point precision limitations
- 0.1 and 0.2 are not stored precisely in binary
- It's a bug in JavaScript
- JavaScript uses a different numeric system
In JavaScript, numbers are represented in binary, and not all decimal fractions can be precisely represented in binary. Due to this limitation, when you perform operations like addition with decimal numbers, you might encounter tiny rounding errors that make 0.1 + 0.2 !== 0.3. This behavior is not unique to JavaScript and occurs in many programming languages with floating-point arithmetic.
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.