What is the primary role of the this keyword in JavaScript?
this
It accesses the global scope.
It refers to the current date and time.
It creates a new object instance.
It points to the object that the function is a property of, determined at function call time.
Which technique can minimize DOM reflows and repaints, leading to smoother UI updates?
Frequently reading element properties like 'offsetWidth'
Using 'innerHTML' to update large sections of the DOM
Making changes to elements with 'display: none'
Batching DOM updates and using 'requestAnimationFrame'
What is the primary difference between 'nextSibling' and 'nextElementSibling' in DOM traversal?
'nextSibling' might return a text node or comment, while 'nextElementSibling' only returns element nodes.
There is no difference; they are interchangeable.
'nextSibling' traverses upwards in the DOM, while 'nextElementSibling' traverses downwards.
'nextSibling' only works with elements, while 'nextElementSibling' works with any node type.
Which method is most efficient for finding a specific element in the DOM based on its ID?
getElementById('my-id')
querySelectorAll('#my-id')[0]
querySelector('#my-id')
getElementsByClassName('my-class')[0]
What is the primary purpose of constructor functions in JavaScript?
To create multiple instances of an object with shared properties and methods.
To define private variables within a function scope.
To handle asynchronous operations.
To define static methods for a class.
What is a primary method for avoiding memory leaks in JavaScript?
Using 'async/await' for all asynchronous operations
Minimizing function calls
Dereferencing unused objects and variables
Using 'const' for all variable declarations
What is the purpose of the response.json() method when using the Fetch API?
response.json()
It parses the response body as JSON data.
It sets the Content-Type header of the request to 'application/json'.
It converts a JavaScript object into a JSON string.
It sends a JSON-encoded request to the server.
Which built-in JavaScript method allows you to pass an array of arguments to a function, effectively spreading them as individual arguments?
call()
spread()
bind()
apply()
Which of these methods allows you to explicitly set the this value when calling a function in JavaScript?
.map()
.forEach()
.filter()
.call()
What is the primary purpose of Promises in JavaScript?
To create loops that iterate over arrays.
To manage asynchronous operations and their results.
To define object-oriented classes.
To handle synchronous operations more efficiently.