What is a key difference between 'async/await' and traditional Promise-based code?
Explanation:
'async/await' is built on top of Promises, offering a cleaner and more readable syntax. It allows you to write asynchronous code that resembles synchronous code, making it easier to understand and maintain.
What does the 'Fetch API' return as the result of a successful network request?
Explanation:
The Fetch API returns a Promise. Upon successful completion of the network request, this Promise resolves with a Response object. The Response object contains information about the response, such as headers and status code, and provides methods to access the response body in various formats.
What is the primary purpose of Promises in JavaScript?
Explanation:
Promises in JavaScript provide a way to handle the outcome of asynchronous operations, whether they succeed or fail. This helps avoid callback hell and makes asynchronous code more readable.
What is a common practice to avoid deeply nested callbacks when working with multiple asynchronous operations?
Explanation:
Promise chaining provides a way to structure asynchronous code sequentially without nesting callbacks deeply. By chaining '.then()' methods, the result of one asynchronous operation is passed to the next, improving readability and maintainability.
How does the 'bind()' method in JavaScript differ from 'call()' and 'apply()'?
Explanation:
The primary distinction lies in their execution behavior. bind()
returns a new function with the context of this
permanently bound, whereas call()
and apply()
execute the function immediately with the specified context.
In the context of ES6 classes, what is the purpose of the 'extends' keyword?
Explanation:
The 'extends' keyword allows you to create a child class that inherits characteristics from a parent class, enabling code reuse and a hierarchical structure.
Which technique can minimize DOM reflows and repaints, leading to smoother UI updates?
Explanation:
Batching updates reduces the number of layout recalculations, and using 'requestAnimationFrame' allows the browser to optimize repaints, resulting in smoother animations and UI changes.
What is the primary role of the this
keyword in JavaScript?
Explanation:
The value of this
is dynamically determined when a function is called, not when it's defined. It's a frequent source of confusion for developers new to JavaScript as it behaves differently compared to many other programming languages.
Which method allows you to move up from a child element to its direct parent in the DOM?
Explanation:
The parentElement
property returns the direct parent element of the current element in the DOM tree. While parentNode
serves a similar purpose, it might return a different node type in situations involving Document Fragments or XML documents.
Which built-in JavaScript method allows you to pass an array of arguments to a function, effectively spreading them as individual arguments?
Explanation:
The apply()
method calls a function with a given this
value and arguments provided as an array. It's used to execute a function with a different context and pass multiple arguments in array form.