Which of the following is a primary use case for stubbing in tests?

  • Capturing and verifying function calls
  • Simulating the behavior of a function or method
  • Mocking external dependencies
  • Generating random test data
Stubbing in tests is often used to simulate the behavior of a function or method, allowing you to control its responses for testing purposes. It's especially useful when you want to isolate the code under test and ensure that certain functions return specific values or execute specific code paths.

How can the process object be used to handle application termination in Node.js?

  • process.exit()
  • process.end()
  • process.terminate()
  • process.halt()
In Node.js, you can use process.exit() to gracefully terminate a Node.js application. It allows you to specify an exit code. The other options, such as process.end(), process.terminate(), and process.halt(), are not valid methods for application termination.

Utilizing closures with caution is essential as they can lead to potential memory leaks due to retained ________.

  • Variables
  • Functions
  • References
  • Objects
Closures retain references to their containing scope, which includes variables and functions. If not managed carefully, this can lead to memory leaks as these references may prevent objects from being garbage collected.

How does cache eviction strategy LRU (Least Recently Used) work?

  • LRU removes the item that was accessed most recently.
  • LRU removes the item that was accessed least recently.
  • LRU removes the item with the smallest key.
  • LRU removes items randomly.
LRU (Least Recently Used) eviction strategy removes the item from the cache that was accessed the least recently. This ensures that the cache retains the most recently accessed items, optimizing for cache hits.

You are tasked with developing a real-time chat application where low latency and high availability are critical. Which type of database would be the most suitable, and what considerations should you have in mind regarding data consistency and partitioning?

  • Relational Database
  • NoSQL Database
  • Graph Database
  • In-Memory Database
For a real-time chat application, a NoSQL database would be most suitable due to its ability to handle high concurrency and unstructured data. Considerations for data consistency would involve choosing an appropriate consistency model, like eventual consistency, and partitioning data for scalability and low latency.

In JavaScript, a closure is created when an inner function accesses the ________ of an outer function after the outer function has executed.

  • parameters
  • variables
  • methods
  • properties
In JavaScript, a closure is created when an inner function accesses the variables of an outer function after the outer function has executed. Closures allow inner functions to "remember" and access the variables of their containing (outer) function even after the outer function has finished executing. This is a fundamental concept for managing scope and data privacy in JavaScript.

You are optimizing the performance of a web application that uses EJS for rendering views. The views have a lot of dynamic content and are currently slow to render. How would you approach optimizing the rendering performance of the EJS templates?

  • Implement caching mechanisms for frequently accessed templates using a caching library like Redis.
  • Minimize the use of JavaScript in templates and offload complex logic to the server-side to reduce client-side rendering time.
  • Precompile EJS templates into JavaScript functions to reduce runtime rendering overhead.
  • Increase the client-side rendering capabilities by using a JavaScript framework like React or Angular.
To optimize the rendering performance of EJS templates, one effective approach is to precompile EJS templates into JavaScript functions. This reduces the runtime rendering overhead and improves the efficiency of rendering dynamic content.

You are developing a critical system where the cost of failure is very high. How would you design your testing strategy to ensure the reliability and stability of the system?

  • Conduct extensive Unit Testing
  • Rely on Beta Testing by end-users
  • Implement Continuous Integration and Continuous Deployment (CI/CD) pipelines
  • Perform thorough Regression Testing and use Automated Testing
To ensure the reliability and stability of a critical system, thorough Regression Testing and the use of Automated Testing are essential. These techniques help catch potential issues early and maintain system stability. Extensive Unit Testing alone may not cover all scenarios, and Beta Testing may be too risky for critical systems. CI/CD pipelines support automation but should be combined with robust testing.

How does JavaScript's dynamic typing affect variable assignments and operations?

  • It enforces strict type checking.
  • It allows variables to change type during runtime.
  • It requires explicit type annotations for all variables.
  • It prevents type errors at compile time.
JavaScript's dynamic typing allows variables to change their data type during runtime. Unlike languages with static typing, you don't need to specify the data type of a variable explicitly.

In Pug, to extend a layout, you use the extends keyword and to fill a block within the layout, you use the ______ keyword.

  • include
  • fill
  • block
  • insert
In Pug, the extends keyword is used to extend a layout, and the block keyword is used to fill a block within the layout. This allows you to create modular and reusable templates. The other options do not serve the same purpose in Pug.

When the Event Loop encounters an asynchronous task, it offloads it to the ________ and continues to execute subsequent tasks.

  • Callback Queue
  • Worker Thread
  • Event Emitter
  • Main Memory
When the Event Loop encounters an asynchronous task, it offloads it to the Callback Queue and continues to execute subsequent tasks. These tasks are then processed from the Callback Queue when the main thread is available.

You are developing an application with multiple user roles, and each role has different levels of access to resources. How would you securely implement role-based access control to prevent unauthorized access?

  • Use JSON Web Tokens (JWT) to manage user sessions and roles.
  • Implement access control lists (ACLs) in your application.
  • Check the user's role in the frontend to determine access.
  • Rely solely on server-side sessions to control access.
Option (1) is correct. Using JWTs for session management and roles is a secure approach as they are self-contained and can be verified without relying on server-side sessions. Options (2) and (4) are less secure and may lead to vulnerabilities. Option (3) is incorrect as access control should be enforced on the server.