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.

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.

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

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.

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.

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.

Cross-Origin Resource Sharing (CORS) is a security feature implemented by web browsers to restrict web pages from making requests to a different domain than the one that served the web page, also known as ________.

  • Same-Origin Policy
  • Cross-Origin Policy
  • Cross-Domain Policy
  • Origin Control Policy
Cross-Origin Resource Sharing (CORS) is a security feature that enforces the Same-Origin Policy, which restricts web pages from making requests to a different domain than the one that served the web page. This helps prevent unauthorized access to data on other domains.

In JavaScript, using the rest operator on the left side of an assignment is called ______.

  • Spreading
  • Unpacking
  • Resting
  • Distributing
In JavaScript, using the rest operator on the left side of an assignment is called "Unpacking." The rest operator allows you to extract values from arrays or objects easily. "Spreading" is the term used when using the spread operator to create copies of arrays or objects.

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.