What is the role of the extends property in an ESLint configuration file?
- It specifies the file extensions to be linted.
- It extends the code editor with ESLint features.
- It defines the list of plugins to use.
- It inherits configurations from other configurations.
The extends property in an ESLint configuration file allows you to inherit configurations from other configurations. It's a way to reuse or build upon existing ESLint configurations, making it easier to enforce consistent coding standards across projects.
You are building a game where a player must answer a series of questions. How would you structure the control flow to handle the player’s responses and determine the next action or question based on the response?
- if...else if...else statements
- switch statement
- try...catch statements
- while loop
To handle the player's responses and determine the next action or question based on the response in a game, you would typically use a series of if...else if...else statements. These conditional statements allow you to evaluate multiple conditions and execute corresponding code blocks based on the player's response. The switch statement can also be used, but it's better suited for cases where you need to match a single value to multiple possible cases. try...catch is used for error handling, and a while loop is generally not suitable for handling player responses in this context.
To handle uncaught exceptions in a Node.js application, you can use process.on('______', callback).
- unhandledRejection
- process.error
- exception
In Node.js, you can handle uncaught exceptions by using the process.on('unhandledRejection', callback) event. This allows you to capture unhandled promise rejections and take appropriate actions.
You are managing a project with multiple dependencies, and you want to ensure that upgrading a dependency doesn't break the project due to API changes. How would you specify the version numbers of the dependencies in the package.json file?
- ^1.0.0
- ~1.0.0
- 1.0.0
- 1.x.x
To ensure that only patch-level changes are allowed for your dependencies, you should use the ~ (tilde) prefix. This will allow for bug fixes (patch versions) but prevent breaking changes (minor or major versions).
The 'highWaterMark' option in Node.js streams denotes the ______ of the internal buffer.
- size
- rate
- capacity
- length
In Node.js streams, the 'highWaterMark' option denotes the capacity of the internal buffer. This value determines how much data the stream can buffer before it starts to pause the data source.
In JavaScript, a for…in loop is used to iterate over the ________ of an object.
- properties
- values
- methods
- variables
In JavaScript, a for...in loop is used to iterate over the properties of an object. It is commonly used for object iteration, and it iterates through the keys or property names of an object.
Which of the following is the correct way to declare a variable in JavaScript?
- var x = 10;
- x := 10;
- int x = 10;
- declare x = 10;
In JavaScript, variables can be declared using the var keyword. The other options are either used in different programming languages or are not valid syntax in JavaScript.
Which of the following is the correct way to parse JSON in the body of a request in Express.js?
- app.use(express.json())
- app.use(body.parse())
- app.use(request.json())
- app.parse(json)
To parse JSON in the body of a request in Express.js, you should use app.use(express.json()). This middleware is used to parse JSON data in the request body. The other options do not represent the correct way to parse JSON in Express.js.
You are working on a project that has several outdated packages with known vulnerabilities. What approach would you take to update those packages while ensuring the stability of the project?
- Update all packages to their latest versions immediately
- Review the changelogs of outdated packages, perform incremental updates, and thoroughly test each update
- Ignore the outdated packages as they may not impact the project
- Downgrade the Node.js version to maintain package compatibility
The correct approach is to review the changelogs of outdated packages, perform incremental updates, and thoroughly test each update. This ensures that updates do not introduce breaking changes and maintain project stability.
When implementing JWT, where is the token commonly stored for subsequent requests?
- In a cookie
- In a URL query parameter
- In a request header
- In a hidden form field
In JWT (JSON Web Tokens), the token is commonly stored in a request header, specifically in the Authorization header using the Bearer scheme. This method is considered secure and widely adopted. Storing the token in a cookie or URL query parameter can have security risks.