Using label with break or continue provides more control over which part of the code to ________ or ________ in JavaScript.
- skip, execute
- terminate, run
- jump, skip
- stop, resume
Using labels with break or continue in JavaScript provides more control over which part of the code to skip or execute. Labels allow you to specify which loop or block of code should be affected by break or continue statements when dealing with nested loops or complex control flow.
What would be the best way to handle errors in an Express application when building RESTful APIs?
- Using try...catch blocks in route handlers
- Sending 404 Not Found for all errors
- Using console.log() for error messages
- Not handling errors, let them crash the server
The best way to handle errors in an Express application when building RESTful APIs is to use try...catch blocks in route handlers. This allows you to catch errors and send appropriate HTTP responses with error details. Sending 404 Not Found for all errors is not a good practice, and letting errors crash the server is even worse. Console.log() is generally used for debugging but not for handling errors.
You are maintaining a library, and you need to release a new version that fixes a bug but also changes the behavior of an existing feature. How should you update the version number according to semantic versioning?
- 1.0.0
- 1.1.0
- 2.0.0
- 1.0.1
According to semantic versioning (SemVer), when you make backward-incompatible changes or breaking changes, you should increment the major version. In this scenario, since the behavior change affects existing users, you should update to version 2.0.0.
Which command is used to install a Node.js package globally?
- npm global install
- npm i -g
- npm install -g
- npm add -g
To install a Node.js package globally, you should use the npm install -g command. This makes the package available for use across different projects. The other options may not work as expected or are not the recommended way to install packages globally.
When implementing indexing, what factors should be considered to mitigate the impact on database write performance?
- Selective indexing
- Index maintenance strategy
- Using index-only scans
- Increasing index size
When implementing indexing, factors to consider for mitigating the impact on write performance include selective indexing (indexing only the columns that are frequently queried), choosing an appropriate index maintenance strategy (e.g., periodic maintenance rather than immediate updates), and using index-only scans to reduce disk I/O during reads. Increasing the index size can have a negative impact on write performance, so it should be done judiciously.
To override ESLint rules for specific files or directories, you can create a .eslintignore or ______ file with the patterns of the files or directories to be excluded.
- .eslintrc.js
- .eslintignore
- .eslintconfig
- .eslintexclude
To override ESLint rules for specific files or directories, you can create a .eslintignore file with patterns of the files or directories to be excluded from ESLint linting. The other options are not used for this purpose.
Which of the following events is emitted when data is available to read from a readable stream?
- data
- readable
- onData
- available
In Node.js, the 'data' event is emitted when data is available to read from a readable stream. This event allows you to consume the data as it becomes available. The other options are not standard events for this purpose.
When performing file operations using the fs module, handling ______ errors is crucial to ensure data integrity.
- synchronous
- asynchronous
- promise
- event
When working with file operations in Node.js using the fs module, handling asynchronous errors is crucial. Asynchronous file operations can fail due to various reasons such as file not found, permission issues, or disk full errors. Proper error handling ensures data integrity and prevents unexpected crashes in your application.
How can you define optional route parameters in Express.js?
- Enclose parameters in square brackets [param]
- Use the optional keyword before the parameter
- Use the ? symbol after the parameter
- Wrap parameters in parentheses (param)
In Express.js, you can define optional route parameters by using the ? symbol after the parameter name, like /route/:param?. This makes the parameter optional, allowing it to match both routes with and without that parameter. The other options do not represent the correct way to define optional route parameters in Express.js.
You are creating a build for a production environment and realize that some of the devDependencies are being included in the build, causing it to be bulkier. What steps would you take to rectify this?
- Manually remove devDependencies from package.json
- Use Webpack to exclude devDependencies
- Use the npm prune --production command
- Upgrade all devDependencies to their latest versions
To rectify this issue, you should use the npm prune --production command. This command removes unnecessary devDependencies from your node_modules directory, ensuring that only production dependencies are included in the build. Options (1) and (4) are not recommended because manually removing or upgrading devDependencies can be error-prone. Option (2) doesn't directly address the issue, and Webpack is typically used for bundling rather than dependency management.