When a JavaScript function is executed, a new execution context is created, and a special object called ________ is created.

  • "this"
  • "global"
  • "function"
  • "execution"
When a JavaScript function is executed, a new execution context is created, and a special object called the "execution context" is created. This execution context contains information about the function's variables and scope.

In a token-based authentication system, using a ______ approach helps in reducing the risk of token interception and replay attacks.

  • Stateless
  • Stateful
  • Hybrid
  • Cookie-based
In a token-based authentication system, a "stateless" approach is used to reduce the risk of token interception and replay attacks. Stateful approaches require server-side storage, while stateless approaches are based on self-contained tokens, which do not rely on server-side storage, making them more secure.

In Node.js, which method is used to establish a connection to a MongoDB database?

  • connectToMongo()
  • openConnection()
  • mongoose.connect()
  • establishMongoDBConnection
In Node.js, the method used to establish a connection to a MongoDB database is mongoose.connect(). Mongoose is a widely used Node.js library for MongoDB that provides an elegant way to define data schemas and interact with MongoDB. The other options do not represent the standard way to connect to a MongoDB database in Node.js.

How can you implement inheritance between two objects in JavaScript?

  • Prototypal Inheritance
  • Object Composition
  • Class Inheritance
  • Functional Inheritance
In JavaScript, inheritance can be implemented through Prototypal Inheritance. Objects can inherit properties and methods from other objects by setting their prototype. The other options describe alternative approaches to code reuse and object creation but don't involve direct inheritance.

When connecting to a SQL database in Node.js, the ______ method is commonly used to execute SQL queries.

  • query()
  • execSQL()
  • runQuery()
  • execute()
When connecting to a SQL database in Node.js, the query() method is commonly used to execute SQL queries. This method is provided by most SQL database libraries for Node.js and allows you to send SQL queries to the database. Options 2, 3, and 4 are not standard methods for executing SQL queries in Node.js.

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.

How can prototype pollution vulnerabilities be mitigated in JavaScript applications?

  • Avoid using third-party libraries
  • Use strong typing for all variables
  • Validate and sanitize user input
  • Disable JavaScript prototypes
To mitigate prototype pollution vulnerabilities in JavaScript applications, it's crucial to validate and sanitize user input. This prevents malicious input from corrupting object prototypes. Avoiding third-party libraries and using strong typing are good practices but do not directly address prototype pollution. Disabling prototypes would break core JavaScript functionality.

You are developing a web application that needs to make API requests to a server on a different domain. How would you handle CORS to ensure that your web application can interact with the server without any issues?

  • Set up a server-side proxy to forward requests to the other domain.
  • Enable CORS on the server by adding appropriate headers to allow cross-origin requests.
  • Use JSONP for making cross-domain requests.
  • Disable CORS restrictions in the browser settings.
The correct approach is to enable CORS on the server by adding the appropriate headers that allow cross-origin requests. Option A can be a workaround, but it's not the best practice. Option C is an outdated method, and option D is not a recommended security practice.

For optimal performance when querying a large dataset in a NoSQL database, it is crucial to have proper ______ in place.

  • Indexing
  • Sharding
  • Versioning
  • Compression
For optimal performance when querying a large dataset in a NoSQL database, it is crucial to have proper indexing in place. Indexes help the database quickly locate and retrieve the data, reducing query response times.

When configuring the static files directory in Express.js, the path specified is relative to the ______ directory.

  • current
  • project
  • root
  • parent
When configuring the static files directory in Express.js, the path specified is relative to the root directory of your project. This means that you specify the path from the root of your project's directory structure.

When designing schemas for large-scale systems, the principle of ________ involves dividing the dataset into smaller, more manageable parts.

  • Sharding
  • Normalization
  • Aggregation
  • Indexing
The principle of "sharding" involves dividing the dataset into smaller, more manageable parts, typically based on a certain criteria like range or hash, to distribute data across multiple servers or nodes in a distributed system. Sharding is a crucial concept in achieving horizontal scalability in databases.

What type of object is passed as the first argument to the request listener function when creating an HTTP server?

  • request
  • response
  • server
  • http
The first argument passed to the request listener function when creating an HTTP server is the request object. This object contains information about the incoming HTTP request, such as headers, URL, and HTTP method. It allows you to read and process client requests.