How does semantic versioning handle pre-release versions and build metadata?

  • Pre-release versions are denoted with a hyphen and can include additional labels and numbers. Build metadata is indicated with a plus sign.
  • Pre-release versions use square brackets to specify additional labels, and build metadata uses parentheses.
  • Pre-release versions are marked with a plus sign, and build metadata is indicated with a hyphen.
  • Pre-release versions are not supported in semantic versioning.
Semantic versioning allows pre-release versions to be denoted with a hyphen, followed by additional labels and numbers, and build metadata is indicated with a plus sign. This is essential for managing versions during development and testing phases.

Why would you use the global object to store data in a Node.js application?

  • To share data between different Node.js modules.
  • To encapsulate data and prevent it from being accessed globally.
  • To improve application performance by reducing memory usage.
  • To ensure data persistence across application runs.
The global object in Node.js can be used to store data that needs to be shared between different Node.js modules. It acts as a global namespace for variables and allows you to share data across different parts of your application. The other options do not accurately describe the common use case for the global object.

When handling errors in an async function, if an error is not caught within the function, it will cause the returned Promise to be in a ________ state.

  • Pending
  • Fulfilled
  • Rejected
  • Completed
When an uncaught error occurs in an async function, the returned Promise will be in a "Rejected" state. In the Promise lifecycle, it can start as "Pending," move to "Fulfilled" upon success, or "Rejected" upon an error.

How does JavaScript handle circular dependencies between modules?

  • JavaScript throws an error and does not allow circular dependencies.
  • JavaScript allows circular dependencies, and they are resolved at runtime.
  • JavaScript handles circular dependencies by allowing them but ensuring that each module loads only once.
  • Circular dependencies are not supported in JavaScript.
JavaScript allows circular dependencies, but it ensures that each module is only executed once. This is achieved through a mechanism called "module caching."

Which keyword is used to export multiple things from a module in JavaScript?

  • import
  • export
  • require
  • module
In JavaScript, the export keyword is used to export multiple things from a module. It allows you to specify which functions, objects, or variables should be accessible from outside the module. The import keyword is used for importing from modules, not exporting. The require and module keywords are used in CommonJS, a different module system.

Which of the following is the primary role of middleware in Express.js?

  • Handling client-side routing
  • Handling server-side routing
  • Managing HTTP requests and responses
  • Creating database schemas
The primary role of middleware in Express.js is to manage HTTP requests and responses. Middleware functions are executed in the order they are defined in the Express application and can perform various tasks such as authentication, logging, and modifying request/response objects. They play a crucial role in the request/response cycle.

In what way does the Event Loop affect the performance of a Node.js application?

  • It can improve performance by handling asynchronous operations efficiently.
  • It slows down the application by blocking all I/O operations.
  • It has no impact on performance.
  • It can only handle synchronous operations.
The Event Loop in Node.js plays a crucial role in improving performance by efficiently handling asynchronous operations. It allows Node.js to execute non-blocking code, ensuring that the application remains responsive and can handle multiple concurrent requests without getting blocked.

To install all the dependencies listed in the package.json file, the ______ command should be used.

  • npm init
  • npm add
  • npm install
  • npm create
To install all the dependencies listed in the package.json file, you should use the npm install command. It reads the dependencies specified in package.json and installs them. The other options are not used for this specific purpose.

You are maintaining a server that has strict security requirements. You need to allow cross-origin requests but with stringent restrictions. How can you implement CORS to fulfill these requirements while maintaining security?

  • Set Access-Control-Allow-Origin to * and rely on server-side authentication.
  • Implement preflight requests with custom headers and allow only authorized clients.
  • Avoid using CORS and handle cross-origin requests through server-side scripting.
  • Enable CORS for all origins and use server-side IP filtering.
To implement stringent security with CORS, you should use preflight requests with custom headers to allow only authorized clients. Option A is not secure as it allows any origin. Option C suggests avoiding CORS altogether, which may not be practical. Option D relies on IP filtering, which can be bypassed.

Express.js middleware functions have access to the ______ object, the ______ object, and a next function in their callback function parameters.

  • request, response
  • response, request
  • req, res
  • req, next
In Express.js middleware functions, the callback function parameters typically include req (the request object) and res (the response object). Additionally, you can use a next function to pass control to the next middleware function in the pipeline. This allows you to manipulate the request and response objects or perform actions before sending a response to the client.

The prototype of an instance object in JavaScript is found using the ______ property.

  • __proto__
  • instanceOf
  • type
  • parent
The __proto__ property is used to access the prototype of an instance object in JavaScript. This is how objects inherit properties and methods from their constructor's prototype.

What is the difference between chaining multiple .then() methods and using multiple await expressions?

  • Chaining .then() is more efficient for error handling
  • Chaining .then() is better for readability
  • Using multiple await expressions allows better error propagation
  • Using multiple await expressions guarantees faster execution
When using await expressions, errors can be propagated using standard try/catch blocks, which allows for more granular and flexible error handling. Chaining multiple .then() methods can lead to less readable and maintainable code when dealing with multiple asynchronous operations. It's not a question of efficiency or speed but rather about readability and error handling.