What is the purpose of 'event.preventDefault()' in JavaScript?
It prevents the default behavior of an element, like a form submission.
It triggers a custom event on an element.
It stops an event from being handled by any further listeners.
It removes an event listener from an element.
Which technique can minimize DOM reflows and repaints, leading to smoother UI updates?
Batching DOM updates and using 'requestAnimationFrame'
Frequently reading element properties like 'offsetWidth'
Making changes to elements with 'display: none'
Using 'innerHTML' to update large sections of the DOM
Consider the code: const myFunc = (a, b) => a + b;. What type of function is myFunc?
const myFunc = (a, b) => a + b;
myFunc
Method
Generator function
Arrow function
Constructor function
What is a common way to achieve encapsulation in JavaScript when modules are not an option (e.g., in older environments)?
Leveraging closures to create private scopes and control access to variables and functions within those scopes.
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.
Using global variables to store private data.
How does the 'bind()' method in JavaScript differ from 'call()' and 'apply()'?
bind() immediately invokes the function, while call() and apply() don't.
bind() doesn't modify the original function, while call() and apply() do.
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.
Which of the following methods is used to handle errors within an 'async/await' function?
.then()
.finally()
.catch()
try...catch block
In JavaScript, how does the prototype chain relate to object inheritance?
The prototype chain manages asynchronous tasks related to object creation.
It's used for event handling and propagation within the DOM.
It establishes a hierarchy for property and method lookup, enabling objects to inherit from prototypes.
The prototype chain determines the order of function execution within an object.
Which keyword is used to define an asynchronous function in JavaScript?
await
promise
async
sync
In what scenario would you typically use a callback function?
To perform an action after an asynchronous operation completes, like fetching data from an API.
To log data to the console for debugging purposes.
To create a loop that iterates a specific number of times.
To define a constant variable.
How can you handle errors inside an async function?
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.