MEAN Trivia 4 — Questions and Answers
Question 1: What Angular directive is used to conditionally show or hide elements in the DOM?
- *ngFor
- *ngIf (Correct answer)
- *ngSwitch
- *ngShow
Correct answer: *ngIf
*ngIf adds or removes an element from the DOM based on a truthy condition.
Question 2: In MongoDB, what is the maximum document size?
- 4 MB
- 8 MB
- 16 MB (Correct answer)
- 32 MB
Correct answer: 16 MB
MongoDB documents have a maximum size of 16 MB; use GridFS for larger files.
Question 3: What is the purpose of Express middleware's `next()` function?
- Sends the HTTP response
- Passes control to the next middleware in the stack (Correct answer)
- Logs the request
- Closes the database connection
Correct answer: Passes control to the next middleware in the stack
Calling next() passes control to the subsequent middleware function in the Express request pipeline.
Question 4: Which Angular lifecycle hook is called once after the component's view is fully initialized?
- ngOnInit
- ngAfterViewInit (Correct answer)
- ngOnChanges
- ngDoCheck
Correct answer: ngAfterViewInit
ngAfterViewInit is called once after Angular has fully initialized the component's view and child views.
Question 5: What does CORS stand for in the context of web development?
- Cross-Origin Resource Sharing (Correct answer)
- Client-Origin Request Service
- Cross-Origin Request Security
- Common Origin Resource Standard
Correct answer: Cross-Origin Resource Sharing
CORS (Cross-Origin Resource Sharing) is a browser security feature that restricts cross-origin HTTP requests.
Question 6: In Mongoose, which method saves a new document to MongoDB?
- .insert()
- .save() (Correct answer)
- .create() only
- .push()
Correct answer: .save()
Calling .save() on a Mongoose document instance persists it to the MongoDB collection.
Question 7: What is the role of `package-lock.json` in a Node.js project?
- Stores environment variables
- Locks exact dependency versions for reproducible installs (Correct answer)
- Lists global npm packages
- Configures Node.js runtime options
Correct answer: Locks exact dependency versions for reproducible installs
package-lock.json locks the exact version of every installed package to ensure consistent installs across environments.
What Angular directive is used to conditionally show or hide elements in the DOM?