Which built-in JavaScript method allows you to pass an array of arguments to a function, effectively spreading them as individual arguments?
bind()
apply()
call()
spread()
How can you ensure that a piece of code runs only after a Promise has been rejected?
By using the '.catch()' method.
By using the '.then()' method.
By using the 'setTimeout()' function.
By placing the code immediately after the Promise is created.
What is a common way to achieve encapsulation in JavaScript when modules are not an option (e.g., in older environments)?
Encapsulation is not achievable without modules in JavaScript.
Relying solely on comments to indicate private members, as there are no built-in mechanisms for true privacy.
Leveraging closures to create private scopes and control access to variables and functions within those scopes.
Using global variables to store private data.
Which method allows you to move up from a child element to its direct parent in the DOM?
parentNode
parentElement
closest()
previousSibling
What is the impact of long-running JavaScript tasks on the browser's responsiveness?
They can block the main thread, leading to a frozen UI and unresponsive interactions.
They improve rendering performance by allowing the browser to optimize resource allocation.
They enhance user experience by providing smoother animations and transitions.
They have no significant impact on browser responsiveness, as JavaScript execution is asynchronous.
How can you handle errors inside an async function?
async
Using a try...catch block.
try...catch
Errors cannot be handled inside async functions.
By calling the .catch() method on the async function itself.
.catch()
By using the throw keyword.
throw
You want to remove the third child element from a parent element with the ID 'container'. What is the correct JavaScript code?
document.getElementById('container').removeChild(2);
document.getElementById('container').children[2].remove();
document.getElementById('container').childNodes[2].remove();
document.getElementById('container').deleteChild(2);
How can you ensure that the 'this' keyword inside a callback function refers to the intended object, especially in asynchronous operations?
By wrapping the callback function in another function.
By invoking the callback function with 'call()' or 'apply()'.
By using the 'let' keyword to declare variables inside the callback.
By using arrow functions, which lexically inherit the 'this' value.
What will be logged to the console in this code snippet: console.log((function(a) { return a * a; })(5));?
console.log((function(a) { return a * a; })(5));
undefined
25
5
10
Which of the following methods is used to handle errors within an 'async/await' function?
.finally()
try...catch block
.then()