MEAN Trivia 5 — Questions and Answers
Question 1: Which Angular decorator is used to inject a service into a component?
- @Inject
- @Injectable
- @Component with providers
- Constructor parameter typing (Correct answer)
Correct answer: Constructor parameter typing
Angular's dependency injection reads TypeScript constructor parameter types to inject services automatically.
Question 2: What MongoDB aggregation stage is used to filter documents, similar to a WHERE clause in SQL?
- $group
- $project
- $match (Correct answer)
- $filter
Correct answer: $match
$match filters documents to pass only those that meet the specified conditions to the next stage.
Question 3: What is the purpose of the `async` and `await` keywords in Node.js?
- Define generator functions
- Handle synchronous callbacks
- Write asynchronous code that reads like synchronous code (Correct answer)
- Create worker threads
Correct answer: Write asynchronous code that reads like synchronous code
async/await is syntactic sugar over Promises that allows asynchronous code to be written in a synchronous style.
Question 4: Which Angular service is used to make HTTP requests to a backend API?
- FetchService
- HttpClient (Correct answer)
- AjaxService
- RequestService
Correct answer: HttpClient
HttpClient from @angular/common/http is Angular's built-in service for making HTTP requests.
Question 5: What does the `--save-dev` flag do when running `npm install`?
- Installs the package globally
- Saves the package as a production dependency
- Saves the package as a development-only dependency (Correct answer)
- Prevents updating package-lock.json
Correct answer: Saves the package as a development-only dependency
--save-dev (or -D) saves the package under devDependencies, so it's excluded from production builds.
Question 6: In Express, which method is used to define a route that responds to all HTTP methods?
- app.use()
- app.all() (Correct answer)
- app.any()
- app.route()
Correct answer: app.all()
app.all() matches all HTTP methods (GET, POST, PUT, etc.) for the specified route path.
Question 7: What Angular pipe is used to format a date in a template?
- dateFormat
- date (Correct answer)
- formatDate
- moment
Correct answer: date
Angular's built-in `date` pipe formats a date value according to locale rules, e.g., {{ today | date:'short' }}.
Which Angular decorator is used to inject a service into a component?