What is the impact of long-running JavaScript tasks on the browser's responsiveness?
They have no significant impact on browser responsiveness, as JavaScript execution is asynchronous.
They enhance user experience by providing smoother animations and transitions.
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.
What is the purpose of the .catch() method in Promise chaining?
.catch()
To transform the resolved value of a Promise.
To filter the results of a Promise.
To handle successful Promise resolutions.
To handle Promise rejections (errors).
Which principle of object-oriented programming focuses on hiding internal implementation details and exposing only necessary information?
Encapsulation
Abstraction
Inheritance
Polymorphism
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 points to the object that the function is a property of, determined at function call time.
It creates a new object instance.
What does the await keyword do inside an asynchronous function?
await
It pauses execution until the Promise it's used with resolves or rejects.
It logs an error message to the console.
It defines a new Promise object.
It sets a timeout before executing the next line of code.
In what scenario would you typically use a callback function?
To create a loop that iterates a specific number of times.
To define a constant variable.
To perform an action after an asynchronous operation completes, like fetching data from an API.
To log data to the console for debugging purposes.
How can you handle errors inside an async function?
async
Errors cannot be handled inside async functions.
By using the throw keyword.
throw
Using a try...catch block.
try...catch
By calling the .catch() method on the async function itself.
Which tool is commonly used for profiling JavaScript code execution and identifying performance bottlenecks?
console.time()
Array.reduce()
Chrome DevTools Performance Tab
JSON.stringify()
How does the 'bind()' method in JavaScript differ from 'call()' and 'apply()'?
bind() doesn't modify the original function, while call() and apply() do.
bind() immediately invokes the function, while call() and apply() don't.
bind() creates a new function with a bound 'this' context, while call() and apply() invoke the function immediately.
bind() can only be used with object methods, while call() and apply() can be used with any function.
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').deleteChild(2);
document.getElementById('container').childNodes[2].remove();