In a Cache-Aside strategy, when is the data loaded into the cache?
- Data is loaded into the cache on write operations.
- Data is loaded into the cache on read operations.
- Data is automatically loaded when the cache is initialized.
- Data is loaded into the cache periodically on a fixed schedule.
In a Cache-Aside strategy, data is not automatically loaded into the cache. Instead, it's loaded explicitly on read operations when an application requests the data.
How does the use of mocking and stubbing affect the isolation of unit tests?
- It increases isolation by replacing real dependencies with controlled substitutes.
- It reduces isolation by relying on actual dependencies.
- It has no effect on isolation.
- It increases isolation by running tests concurrently.
The use of mocking and stubbing in unit tests increases isolation by replacing real dependencies, such as external services or APIs, with controlled substitutes. This allows you to focus on testing the specific unit of code without worrying about the behavior of the real dependencies. Option (2) is incorrect because relying on actual dependencies doesn't create isolation in unit tests. Options (3) and (4) are also incorrect.
How can middleware be added to an Express application to process requests?
- Using the use() method
- Using the get() method
- Using the addMiddleware() function
- Using the handleRequest() method
Middleware can be added to an Express application using the use() method. This method allows you to specify middleware functions that can process requests in the order they are defined. The other options are not standard ways of adding middleware in Express.
Which of the following array methods does not mutate the original array in JavaScript?
- splice()
- push()
- concat()
- pop()
The concat() method in JavaScript creates a new array that combines the elements of the original array and the elements passed as arguments, without modifying the original array. The other methods, such as splice(), push(), and pop(), directly modify the original array.
The fs.createReadStream method is particularly useful when dealing with ______ sized files.
- small
- large
- binary
- text
The fs.createReadStream method in Node.js is particularly useful when dealing with large sized files. This method allows you to efficiently read large files in smaller chunks, which can be memory-efficient for handling large datasets.
What happens to the Event Loop when the callback queue and the task queue are both not empty?
- It suspends the Event Loop until both queues are empty.
- It processes callbacks from the callback queue before tasks from the task queue.
- It processes tasks from the task queue before callbacks from the callback queue.
- It randomly selects items to process from both queues.
When both the callback queue and the task queue are not empty, the Event Loop in Node.js follows a specific order. It first processes callbacks from the callback queue before moving to tasks from the task queue. This order ensures that callback functions, which often include I/O operations, are handled promptly.
In JavaScript, a function that is defined inside another function has access to the outer function's variables, forming a ________.
- Closure
- Enclosure
- Junction
- Intersection
In JavaScript, when a function is defined inside another function, it forms a "closure." A closure allows the inner function to access the outer function's variables even after the outer function has finished executing.
To perform an action once a Promise is settled, regardless of its outcome, you can use the .finally() method, which is called on the ________ of a Promise.
- rejection
- resolution
- completion
- termination
To perform an action once a Promise is settled, regardless of whether it's fulfilled or rejected, you can use the .finally() method. This method is called on the "completion" of a Promise. It's often used for cleanup operations.
You are tasked with implementing an authentication system for your Express API. What considerations should you make regarding security, user experience, and scalability when choosing an authentication strategy?
- Use JWT (JSON Web Tokens) with long expiration times.
- Store plain text passwords in the database.
- Implement OAuth 2.0 for social login only.
- Use basic authentication over HTTP.
Using JWT with long expiration times might seem like a convenient option for user experience, but it could pose a security risk. Storing plain text passwords is a severe security vulnerability. Implementing OAuth 2.0 for social login only might not be sufficient for all authentication needs. Using basic authentication over HTTP is not secure. A robust authentication strategy should consider security (option 1) without compromising user experience and
You are building a dynamic form generator. You need to ensure that the data types of the input values are preserved when sent to the server. What approach should you take for data type preservation when stringifying the inputs?
- JSON.stringify(inputs);
- inputs.toString();
- String(inputs);
- inputs.join(",");
To preserve data types when stringifying inputs, you should use JSON.stringify(inputs);. This method serializes data to a JSON string, which can later be parsed back into their original data types. The other options do not provide the same level of data type preservation.