Async JavaScript cross interview #5
Async JavaScript:
- What is the purpose of timers in JavaScript, and how do they work?
- Explain the difference between
setTimeout() and setInterval().
- How can you stop the execution of a function set with
setInterval() in JavaScript?
- How can you pass a value to the parameter of a callback function in
setTimeout?
- What is a
Promise in JavaScript, and how does it handle asynchronous operations?
- What are the possible states of a Promise, and what does each state signify?
- What static methods of Promises are you familiar with in JavaScript?
- How do
Promise.all() and Promise.race() differ in their usage?
- Provide an example of chaining multiple promises together.
- What is the significance of handling errors at different points in the chain?
- How can you handle errors in a promise chain?
- Explain how
async and await enhance the readability of asynchronous code.
JavaScript Errors:
- What is the purpose of the
try..catch statement in JavaScript?
- How does error propagation work in a synchronous JavaScript function?
- Explain the differences between a
SyntaxError and a TypeError in JavaScript.
- How can you
create and throw a custom error in JavaScript?
- What is the significance of the
finally block in error handling?
- Provide an example where
throw is used within a function.
- How can custom errors be used to enhance debugging and error handling?
- When would capturing stack traces be beneficial in error management?
- Describe how unhandled errors in Promises are different from those in synchronous code.
- How can the Error constructor be used to enhance thrown exceptions?
Event loop (V8 & NodeJS):
- What is the event loop in JavaScript, and why is it crucial?
- Describe the difference in event loop mechanisms between browsers (like Chrome’s V8 engine) and Node.js.
- How do microtasks and macrotasks impact the execution of JavaScript code?
- How does the call stack interact with the event loop in handling function execution?
- What role do Web APIs play in the event loop process within browser environments?
- What happens in the event loop when a JavaScript execution stack is full?
- How does the event loop handle high-priority tasks such as user input or animations?
- How does the event loop prioritize different types of callbacks, such as those from setTimeout, setImmediate, and I/O operations?