When using the map method on an array in JavaScript, the original array ______ be mutated.

  • may
  • will
  • must
  • can't
When using the map method on an array in JavaScript, the original array can't be mutated. The map method creates a new array with the results of calling a provided function on every element in the original array without changing the original array itself.

Which of the following is a suitable method to prevent variable leakage in the global scope?

  • Using the var keyword to declare variables.
  • Using immediately-invoked function expressions (IIFE).
  • Using global variables exclusively.
  • Using let and const keywords to declare variables.
Using immediately-invoked function expressions (IIFE) is a common technique to prevent variable leakage into the global scope. It encapsulates variables within a function scope, avoiding global pollution. The other options do not address this concern effectively.

How can you install ESLint in your Node.js project?

  • Using npm or yarn: npm install eslint --save-dev or yarn add eslint --dev
  • Downloading it from the official website
  • Installing it globally using npm install -g eslint
  • Adding it directly to your HTML file
You can install ESLint in your Node.js project using npm or yarn by running the command npm install eslint --save-dev or yarn add eslint --dev. This ensures that ESLint is added as a development dependency for your project.

You are tasked with improving the performance of a database that experiences heavy read and write operations. How would you balance the use of indexing to improve read performance while minimizing the impact on write performance?

  • Add Indexes to All Columns for Faster Reads
  • Use Covering Indexes for Frequently Queried Columns
  • Implement Partitioned Tables to Isolate Write-Intensive Data
  • Regularly Rebuild All Indexes for Maximum Performance
To balance the use of indexing in a database with heavy read and write operations, it's crucial to use Covering Indexes for frequently queried columns. These indexes include all the necessary data for the query, reducing the need to access the main table. Implementing Partitioned Tables can isolate write-intensive data from read-intensive data, improving write performance. Adding indexes to all columns and regularly rebuilding all indexes can lead to unnecessary overhead and hinder write performance.

Which method in Express.js is used to serve static files?

  • app.static()
  • app.useStatic()
  • app.serveStatic()
  • app.use()
In Express.js, the app.use(express.static()) method is used to serve static files. This method allows you to specify a directory from which Express should serve static assets like images, CSS, and JavaScript. The other options are not valid methods for serving static files in Express.

In Express.js, the ______ method is commonly used to protect routes and ensure that only authenticated users can access them.

  • authenticate
  • secure
  • authorize
  • validate
In Express.js, the authorize method is commonly used to protect routes and ensure that only authenticated users can access them. This is often achieved through middleware functions that check for authentication and authorization before allowing access. The other options may not be standard methods for this purpose in Express.js.

What is the significance of the HTTP status code in the response of an Express API, and how does it affect client-server interaction?

  • HTTP status codes are optional and don't impact client-server interaction
  • HTTP status codes indicate the type of response and guide client behavior
  • HTTP status codes are primarily for server documentation
  • HTTP status codes are used to encrypt the API response
HTTP status codes are essential in the response of an Express API. They indicate the type of response and guide client behavior. For example, a 200 OK status indicates success, while a 404 Not Found status indicates a resource was not found. Proper status codes enhance communication and handling between the client and server.

Connection to a NoSQL database like MongoDB in Node.js usually returns a ______ object.

  • MongoClient
  • Promise
  • HttpServer
  • Buffer
When connecting to a NoSQL database like MongoDB in Node.js, you typically get a MongoClient object. This object represents the database connection and allows you to perform various database operations. The other options are not related to MongoDB connections.

Which method should be used to handle the rejection of a Promise?

  • reject()
  • catch()
  • error()
  • failure()
To handle the rejection of a Promise, you should use the catch() method. It allows you to specify what to do when the Promise is rejected with an error. The other options are not standard methods for handling Promise rejection in JavaScript.

In the context of security, what does the principle of "least privilege" mean?

  • Giving users the fewest privileges necessary to perform their tasks
  • Giving users all possible privileges
  • Giving administrators fewer privileges than regular users
  • Giving privileges based on user seniority
The principle of "least privilege" means giving users the fewest privileges necessary to perform their tasks. This reduces the risk of unauthorized access and potential security breaches. The other options do not align with this security principle.