In JavaScript, ______ is a primitive data type that can only have values true or false.

  • boolean
  • binary
  • logical
In JavaScript, the boolean data type is a primitive type that can only have values true or false. It is commonly used for representing logical values in conditional statements and comparisons.

Which HTTP method is used by the browser to send a preflight request?

  • GET
  • POST
  • OPTIONS
  • HEAD
The browser uses the HTTP OPTIONS method to send a preflight request when making a cross-origin request with certain headers or methods that may require server approval. The server should respond to the preflight request with appropriate CORS headers to indicate whether the actual request is allowed. The other HTTP methods are not used for preflight requests.

How can you access query parameters in Express routes?

  • Using req.query
  • Using req.params
  • Using req.body
  • Using req.header
In Express, query parameters can be accessed using the req.query object. These parameters are typically included in the URL after a ? character and are used to send additional data to the server. req.params is used for route parameters, req.body for POST request data, and req.header for request headers.

To match a route for any HTTP method in Express.js, you can use the ______ method.

  • app.use
  • app.get
  • app.all
  • app.route
In Express.js, the app.all method is used to match a route for any HTTP method. It is often used for middleware that should apply to all HTTP methods for a specific route. The other options are specific to certain HTTP methods (app.get for GET requests, app.use for middleware, and app.route for creating route handlers).

You are developing a web application with various user roles, each with different access levels to the application’s resources. How would you design the authorization system to ensure proper access control, scalability, and maintainability?

  • Use a single "admin" role for all users
  • Implement access control checks within route handlers
  • Use a role-based access control (RBAC) system
  • Give every user full access to all resources
To ensure proper access control, scalability, and maintainability in a web application with multiple user roles, you should use a role-based access control (RBAC) system. RBAC allows for fine-grained control over user permissions and is scalable as your application grows. The other options are not recommended, as they lack proper access control or are not scalable.

What is the significance of the async keyword in JavaScript?

  • It defines a function that returns a Promise, allowing asynchronous operations.
  • It makes a function execute synchronously.
  • It is used to declare a variable as asynchronous.
  • It enables the use of callbacks.
The async keyword is used to define a function as asynchronous, meaning it returns a Promise. This allows you to perform non-blocking operations, making JavaScript code more efficient.

How can you store and retrieve uploaded files efficiently in a cloud storage service?

  • Store files directly in the database.
  • Use a Content Delivery Network (CDN) for file storage.
  • Store files on the web server's local file system.
  • Compress all uploaded files into a single archive.
An optimal approach for storing and retrieving uploaded files efficiently in a cloud storage service is to use a Content Delivery Network (CDN). CDNs are designed to distribute content across multiple servers, reducing latency and enhancing scalability, making them ideal for serving files to users. Storing files directly in the database or on the web server's local file system can lead to performance issues and scalability challenges. Compressing files into a single archive is not a recommended approach for efficient retrieval.

Which of the following is used to perform a conditional (ternary) operation in JavaScript?

  • if-else
  • switch
  • ?:
  • for
The ?: operator is known as the ternary operator in JavaScript and is used for conditional operations. It allows you to perform a quick inline conditional check and return one of two values based on the condition. The other options (if-else, switch, for) are not used for conditional operations in the same way.

______ caching involves storing cache data in the client's browser to reduce server load and increase load speed.

  • Server-side
  • Client-side
  • In-memory
  • Distributed
Client-side caching involves storing cache data in the client's browser to reduce server load and increase load speed. This can be achieved using techniques like browser caching and local storage.

Which method in Express is used to handle HTTP GET requests to a specified route?

  • app.post()
  • app.get()
  • app.route()
  • app.put()
In Express, the app.get() method is used to handle HTTP GET requests to a specified route. This method is a part of the Express application instance (app) and is used to define routes that respond to HTTP GET requests. The other options (app.post(), app.route(), and app.put()) are used for handling other HTTP methods (POST, routing, and PUT) respectively.

How can you secure sensitive information like API keys in your Express application?

  • Store API keys in plain text within your code
  • Use environment variables to store API keys
  • Embed API keys in the URL parameters
  • Include API keys in the client-side JavaScript
To secure sensitive information like API keys in an Express application, it is essential to use environment variables. Storing API keys in plain text within your code is not secure, embedding them in URL parameters can expose them, and including them in client-side JavaScript makes them accessible to anyone inspecting the client code.

In a distributed caching system, how is cache coherence typically maintained?

  • Using a consistency protocol like "invalidation"
  • By periodically clearing the cache
  • Through manual intervention by administrators
  • Automatically with a "write-through" strategy
Cache coherence in a distributed caching system is typically maintained using a consistency protocol like "invalidation." This protocol ensures that cached data is invalidated or updated when changes occur, ensuring data consistency across distributed nodes.