In Express.js, how can middleware be utilized to implement authorization checks for different routes?

  • Middleware can't be used for authorization checks in Express.js.
  • Middleware functions can be added to route definitions to execute specific authorization logic before handling a request.
  • Middleware can only be used for logging purposes in Express.js.
  • Authorization checks can only be done in the route handler functions.
Middleware in Express.js is versatile and can be used for various purposes, including implementing authorization checks. By adding middleware functions to specific route definitions, you can ensure that certain authorization logic is executed before the route handler processes the request.

How can the 'done' callback be used in asynchronous testing with Mocha?

  • done is used to terminate the Mocha test suite prematurely.
  • done is used to indicate that the test is asynchronous and should wait for it to complete.
  • done is used to skip a test case in Mocha.
  • done is not used in Mocha for asynchronous testing.
In Mocha, the done callback is used to indicate that a test is asynchronous and should wait for it to complete before considering the test case finished. It prevents the test case from finishing prematurely. The other options provide incorrect information about the use of done.

How can you create an object in JavaScript that does not inherit the prototype from Object?

  • Object.create(null)
  • Object() constructor
  • {} constructor
  • Object.assign({})
In JavaScript, you can create an object that does not inherit the prototype from Object by using Object.create(null). This creates an object with no prototype, making it a clean slate. The other options either inherit from Object or use Object's prototype.

In Express, how can you enable Cross-Origin Resource Sharing (CORS) for your API?

  • app.use(cors())
  • app.enable(cors)
  • app.allow(CORS)
  • app.cors(true)
To enable Cross-Origin Resource Sharing (CORS) in Express, you should use the cors middleware by adding app.use(cors()) to your application. This middleware allows or restricts cross-origin HTTP requests. The other options are not valid ways to enable CORS in Express.

What is the primary purpose of using JSON Web Tokens (JWT) in authentication?

  • Storing user passwords securely
  • Encoding user data in URL parameters
  • Storing user sessions on the server
  • Securely transmitting information between parties
The primary purpose of using JSON Web Tokens (JWT) in authentication is to securely transmit information between parties. JWTs are used to authenticate users and ensure that data exchanged between the client and server remains tamper-proof and confidential. They are commonly used in web applications to maintain user sessions without the need to store session data on the server. The other options do not represent the primary purpose of JWTs.

In JavaScript, altering an object’s prototype at runtime can lead to ______ performance impacts.

  • Positive
  • Negative
  • No
  • Minimal
In JavaScript, altering an object's prototype at runtime can lead to "Negative" performance impacts. Modifying prototypes at runtime can cause performance bottlenecks, as it can affect the behavior of all objects that share the same prototype. It's generally recommended to avoid such runtime modifications for performance reasons.

What is the difference between the == and === operators in JavaScript?

  • == compares values for equality, === compares values and types for equality
  • == compares values and types for equality, === compares values for equality
  • == is used for assignment, === is used for comparison
  • == performs a deep comparison, === performs a shallow comparison
In JavaScript, == (loose equality) compares values for equality but performs type coercion if the operands have different types. === (strict equality) compares both values and types for equality without type coercion. Option 1 correctly describes this important distinction.

How does ESLint's --fix option handle issues that it can't automatically fix?

  • ESLint raises an error and stops
  • It logs the issues without attempting to fix them
  • It automatically disables the rule causing the issue
  • It leaves the issues as is
When ESLint's --fix option encounters issues it can't automatically fix, it will disable the rule causing the issue to prevent further errors. This allows ESLint to continue running and fix as many issues as possible without breaking. The other options do not accurately describe how --fix behaves.

How can you ensure that your project’s dependencies are secure and up-to-date?

  • Ignore dependency updates to maintain stability.
  • Regularly review and update dependencies using a tool like npm audit or yarn audit.
  • Rely on the package maintainers to keep dependencies secure.
  • Never update dependencies to avoid breaking changes.
To ensure that your project's dependencies are secure and up-to-date, you should regularly review and update them using tools like npm audit or yarn audit. These tools help identify and address security vulnerabilities. Ignoring updates may lead to security risks, and relying solely on package maintainers is not a recommended practice. Avoiding updates altogether is not a solution as it can lead to outdated and potentially insecure dependencies.

In Jest, to isolate a module from its dependencies for more focused unit testing, you would use ______.

  • mock
  • stub
  • spy
  • inject
In Jest, you can use the mock function to isolate a module from its dependencies. This allows you to replace the real dependencies with mock implementations for focused unit testing.