You are developing a critical system where the cost of failure is very high. How would you design your testing strategy to ensure the reliability and stability of the system?

  • Conduct extensive Unit Testing
  • Rely on Beta Testing by end-users
  • Implement Continuous Integration and Continuous Deployment (CI/CD) pipelines
  • Perform thorough Regression Testing and use Automated Testing
To ensure the reliability and stability of a critical system, thorough Regression Testing and the use of Automated Testing are essential. These techniques help catch potential issues early and maintain system stability. Extensive Unit Testing alone may not cover all scenarios, and Beta Testing may be too risky for critical systems. CI/CD pipelines support automation but should be combined with robust testing.

How does JavaScript's dynamic typing affect variable assignments and operations?

  • It enforces strict type checking.
  • It allows variables to change type during runtime.
  • It requires explicit type annotations for all variables.
  • It prevents type errors at compile time.
JavaScript's dynamic typing allows variables to change their data type during runtime. Unlike languages with static typing, you don't need to specify the data type of a variable explicitly.

In Pug, to extend a layout, you use the extends keyword and to fill a block within the layout, you use the ______ keyword.

  • include
  • fill
  • block
  • insert
In Pug, the extends keyword is used to extend a layout, and the block keyword is used to fill a block within the layout. This allows you to create modular and reusable templates. The other options do not serve the same purpose in Pug.

When the Event Loop encounters an asynchronous task, it offloads it to the ________ and continues to execute subsequent tasks.

  • Callback Queue
  • Worker Thread
  • Event Emitter
  • Main Memory
When the Event Loop encounters an asynchronous task, it offloads it to the Callback Queue and continues to execute subsequent tasks. These tasks are then processed from the Callback Queue when the main thread is available.

You are developing an application with multiple user roles, and each role has different levels of access to resources. How would you securely implement role-based access control to prevent unauthorized access?

  • Use JSON Web Tokens (JWT) to manage user sessions and roles.
  • Implement access control lists (ACLs) in your application.
  • Check the user's role in the frontend to determine access.
  • Rely solely on server-side sessions to control access.
Option (1) is correct. Using JWTs for session management and roles is a secure approach as they are self-contained and can be verified without relying on server-side sessions. Options (2) and (4) are less secure and may lead to vulnerabilities. Option (3) is incorrect as access control should be enforced on the server.

You are integrating ESLint into a legacy project. How would you approach linting the existing codebase without disrupting the development workflow?

  • Lint the entire codebase in one go and fix all issues immediately.
  • Gradually introduce ESLint, starting with new code and addressing legacy code issues incrementally.
  • Disable ESLint for the legacy code and only apply it to new code.
  • Ignore linting in legacy projects as it can't be easily integrated.
To avoid disruption, it's best to gradually introduce ESLint. Start by applying it to new code and address legacy code issues incrementally. Linting the entire codebase at once might be overwhelming and disruptive. Disabling ESLint for legacy code or ignoring it is not a recommended approach for maintaining code quality.

What does the return statement do in a JavaScript function?

  • Returns a value from the function and exits the function
  • Declares a variable
  • Creates a loop
  • Includes a comment in the code
The return statement in a JavaScript function is used to return a value from the function and immediately exit the function. It is used to send data back to the caller of the function. The other options do not describe the purpose of the return statement.

When would you use export default over named exports in a module?

  • export default is used when you want to export multiple values from a module as an object with named keys.
  • export default is used when you want to export a single value, function, or class from a module.
  • export default is used when you want to export a module without specifying a name for it.
  • export default is used when you want to create a private module that can't be imported from other modules.
export default is used when you want to export a single value, function, or class as the default export of a module. This allows you to import it using any name you prefer when importing. Named exports are used when you want to export multiple values with specific names.

You need to expose a global utility function that should be accessible across different modules in your Node.js application. How would you leverage the global object to achieve this?

  • global.utility = require('./utility');
  • global.util = require('./utility');
  • global.import('./utility')
  • global.include('./utility')
To expose a global utility function in Node.js, you can use global.utility = require('./utility');. This allows you to require the module once and make it accessible globally across different modules. The other options do not achieve this in the correct way.

When publishing a package to the NPM registry, what file is crucial to define the package properties and dependencies?

  • package-config.json
  • dependencies.json
  • package-lock.json
  • package.json
When publishing a package to the NPM registry, the package.json file is crucial. This file contains metadata about the package, including its name, version, description, entry points, and most importantly, its dependencies. The package-lock.json file is used to lock dependency versions but is not responsible for defining the package properties. Options 1 and 2 do not exist, and option 3, while related, is not used for defining package properties.

Why is it advantageous to use stubbing when dealing with external services or APIs in tests?

  • Stubbing allows you to make actual API calls during testing.
  • Stubbing provides better performance in tests.
  • Stubbing isolates your tests from the external services, making tests more reliable and faster.
  • Stubbing is required by external services for testing.
It is advantageous to use stubbing when dealing with external services or APIs in tests because stubbing isolates your tests from the actual external services, making tests more reliable and faster. With stubbing, you can control the responses from external services, ensuring that your tests are not affected by changes or issues with the real services. Options (1), (2), and (4) do not accurately describe the advantages of stubbing in this context.

In a RESTful API, which HTTP method corresponds to the Update operation in CRUD?

  • GET
  • POST
  • PUT
  • DELETE
In a RESTful API, the PUT HTTP method corresponds to the Update operation in CRUD (Create, Read, Update, Delete). It is used to update or modify an existing resource on the server.