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.

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 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.

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 you ensure the security of file uploads in a web application?

  • Use an unauthenticated endpoint
  • Limit file size
  • Disallow specific file types
  • Perform server-side validation
To ensure the security of file uploads in a web application, it's crucial to perform server-side validation. This includes checking the file's content type, verifying its size, and possibly scanning it for malware. Other important security measures include limiting file sizes to prevent denial-of-service attacks and disallowing specific file types to prevent the upload of potentially harmful files. Using an unauthenticated endpoint is not recommended as it could lead to security vulnerabilities.

In JavaScript, altering an object’s prototype at runtime can lead to ______ performance impacts.

  • Positive
  • Negative
  • No
  • Minimal
In JavaScript, altering an object's prototype at runtime can lead to "Negative" performance impacts. Modifying prototypes at runtime can cause performance bottlenecks, as it can affect the behavior of all objects that share the same prototype. It's generally recommended to avoid such runtime modifications for performance reasons.

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.

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.

When publishing a package to the NPM registry, what file is crucial to define the package properties and dependencies?

  • package-config.json
  • dependencies.json
  • package-lock.json
  • package.json
When publishing a package to the NPM registry, the package.json file is crucial. This file contains metadata about the package, including its name, version, description, entry points, and most importantly, its dependencies. The package-lock.json file is used to lock dependency versions but is not responsible for defining the package properties. Options 1 and 2 do not exist, and option 3, while related, is not used for defining package properties.

You need to expose a global utility function that should be accessible across different modules in your Node.js application. How would you leverage the global object to achieve this?

  • global.utility = require('./utility');
  • global.util = require('./utility');
  • global.import('./utility')
  • global.include('./utility')
To expose a global utility function in Node.js, you can use global.utility = require('./utility');. This allows you to require the module once and make it accessible globally across different modules. The other options do not achieve this in the correct way.