You are designing a library to manage multiple user sessions in a web application. How can closures be efficiently used to manage individual session states securely?
- Store session data in global variables
- Use closures to encapsulate session data within functions
- Use cookies to store session data
- Use session variables provided by the web framework
Closures in JavaScript can be used to encapsulate session data within functions, providing a secure and isolated way to manage individual session states. Storing session data in global variables (option a) is not secure and can lead to data leakage. Using cookies (option c) is a separate technique for session management, and session variables provided by a web framework (option d) are framework-specific and may not utilize closures.
Loading...
Related Quiz
- What type of object is passed as the first argument to the request listener function when creating an HTTP server?
- What is the proper way to handle errors in EJS views?
- In a complex CORS scenario, how can you selectively allow certain types of requests while denying others?
- Which of the following is the correct way to parse JSON in the body of a request in Express.js?
- When performing CRUD operations on a database, which operation can be the most expensive in terms of performance?