1. What is the primary purpose of the event loop in JavaScript?
A) To block the execution of code
B) To allow non-blocking I/O operations
C) To handle synchronous tasks only
D) To manage multi-threading
Show Explanation
2. What is the purpose of the call stack in JavaScript?
A) To manage function execution contexts
B) To store asynchronous tasks
C) To queue tasks for execution
D) To handle global variables
Show Explanation
3. What is the difference between microtasks and macrotasks?
A) Macrotasks are executed before microtasks
B) Microtasks have higher priority than macrotasks
C) There is no difference
D) Both are executed simultaneously
Show Explanation
4. What is the purpose of the Promise constructor in JavaScript?
A) To create new Promises
B) To execute synchronous code
C) To block the execution
D) To handle all tasks
Show Explanation
5. What is the main difference between local storage and session storage?
A) Local storage persists after closing the browser
B) Session storage can store larger amounts of data
C) Local storage is limited to a single session
D) There is no difference
Show Explanation
6. How do cookies differ from local storage and session storage in terms of expiration?
A) Cookies cannot expire
B) Cookies can have expiration dates
C) Local storage expires after a session
D) There is no difference
Show Explanation
7. What is the primary purpose of the Fetch API in JavaScript?
A) To make HTTP requests
B) To store data in local storage
C) To create cookies
D) To manage sessions
Show Explanation
8. What does the Fetch API return upon making a request?
A) An object with data
B) A Promise
C) An XMLHttpRequest
D) A string
Show Explanation
9. How do you handle the fulfilled state of a Promise in JavaScript?
A) By using the 'then' method
B) By using the 'catch' method
C) By using the 'finally' method
D) By using the 'resolve' method
Show Explanation
10. When is session storage cleared in a web browser?
A) When the browser is closed
B) When the browser tab is closed
C) After a set time
D) When the user logs out
Show Explanation
11. In the event loop, where does a setTimeout callback go after the delay has elapsed?
A) The call stack
B) Microtask queue
C) The global context
D) Macrotask queue
Show Explanation
12. Where do Promises get placed in the event loop when they are resolved?
A) Microtask queue
B) Macrotask queue
C) The call stack
D) Global context
Show Explanation
13. How can you handle a rejected Promise in JavaScript?
A) By using the resolve method
B) By using the finally method
C) By using the catch method
D) By using the complete method
Show Explanation
14. What is a key difference between session storage and local storage?
A) Session storage is specific to a single tab
B) Local storage cannot store strings
C) Session storage does not clear on tab close
D) Local storage expires after a session
Show Explanation
15. What does the 'await' keyword do in an async function?
A) It executes code asynchronously
B) It creates a new Promise
C) It pauses execution until the Promise resolves
D) It throws an error
Show Explanation
16. What type of object does the Fetch API return?
A) A Promise
B) A callback function
C) A JSON object
D) An array
Show Explanation
17. How can you handle a Fetch API response in JavaScript?
A) By using async/await
B) By using a loop
C) By using a setTimeout
D) By storing it in local storage
Show Explanation
18. How can you parse JSON data from a Fetch API response?
A) By using JSON.parse(response)
B) By using response.parseJSON()
C) By using .text()
D) By using .json()
Show Explanation
19. Which storage method can be accessed by both client and server?
A) Cookies
B) Local storage
C) Session storage
D) Both session storage and local storage
Show Explanation
20. Which of the following is processed after the microtask queue?
A) Call stack
B) Task queue
C) Microtask queue again
D) Event queue
Show Explanation