Which of the following methods is used to handle errors within an 'async/await' function?
.catch()
.then()
.finally()
try...catch block
What is a key difference between 'async/await' and traditional Promise-based code?
'async/await' doesn't use Promises internally.
'async/await' is suitable for handling synchronous operations only.
'async/await' is significantly slower than using Promises directly.
'async/await' provides a more synchronous-looking syntax for asynchronous code.
How do ES6 classes simplify object-oriented programming in JavaScript compared to constructor functions?
ES6 classes are primarily used for working with the DOM and have limited object-oriented capabilities.
ES6 classes introduce a completely new inheritance model unrelated to prototypes.
Classes eliminate the need for prototypes, making object creation more efficient.
Classes offer a more concise and familiar syntax for defining objects and inheritance, though they still utilize prototypes under the hood.
Which method is most efficient for finding a specific element in the DOM based on its ID?
querySelector('#my-id')
getElementById('my-id')
querySelectorAll('#my-id')[0]
getElementsByClassName('my-class')[0]
In JavaScript's event loop, what is the role of the 'microtask queue'?
It executes tasks that have been explicitly delayed with setTimeout.
It processes promises and other tasks with higher priority than the main task queue.
It handles user interactions like clicks and scrolls.
It manages network requests and responses.
What is the primary difference between 'nextSibling' and 'nextElementSibling' in DOM traversal?
'nextSibling' traverses upwards in the DOM, while 'nextElementSibling' traverses downwards.
'nextSibling' might return a text node or comment, while 'nextElementSibling' only returns element nodes.
'nextSibling' only works with elements, while 'nextElementSibling' works with any node type.
There is no difference; they are interchangeable.
You need to add an event listener to a dynamically created element. What technique should you use?
Attach the listener to the element's parent using event bubbling.
Directly attach the listener to the element before appending it to the DOM.
Use setTimeout to delay the listener attachment until after the element is added to the DOM.
setTimeout
Event delegation: attach the listener to a parent element that already exists in the DOM.
What is a common practice to avoid deeply nested callbacks when working with multiple asynchronous operations?
Employing synchronous functions exclusively.
Switching to a different programming language.
Using nested 'try...catch' blocks extensively.
Chaining multiple '.then()' methods together.
Consider the code: const myFunc = (a, b) => a + b;. What type of function is myFunc?
const myFunc = (a, b) => a + b;
myFunc
Constructor function
Generator function
Arrow function
Method
You have a form with client-side validation. What is the recommended approach to prevent form submission if validation fails?
Use event.preventDefault() and handle the submission logic manually.
event.preventDefault()
Use event.stopPropagation() to stop the submission event.
event.stopPropagation()
Remove the 'submit' attribute from the form element dynamically.
Set the form's 'action' attribute to an empty string.