Monday, October 28, 2024

TCS Wings 1 T1 MERN - Set 4

Rahul Vijayan
Follow for more updates

TCS Wings 1 T1 MERN - Set 4 

  1. Mason is using MongoDB and needs to filter documents by a field value. Which method should he use to filter data within the MongoDB collection?
  • a) aggregate
  • b) find
  • c) sort
  • d) group

Answer: b) find


  1. Isla is optimizing her React app by using useCallback to memoize a function that gets called in a useEffect. What does useCallback specifically help prevent?
  • a) Prevents component unmounting
  • b) Prevents unnecessary re-renders of a function
  • c) Prevents memory leaks
  • d) Prevents updating the state

Answer: b) Prevents unnecessary re-renders of a function


  1. Oliver is using Express and wants to set up a route that requires authentication. Which status code should he return if a user tries to access it without being logged in?
  • a) 200
  • b) 401
  • c) 404
  • d) 500

Answer: b) 401


  1. Grace wants to apply custom error handling to an asynchronous route in her Express app. What should she use to catch errors in asynchronous functions?
  • a) try-catch block
  • b) await
  • c) setTimeout
  • d) throw

Answer: a) try-catch block


  1. Leo is fetching data from an API in his React component using useEffect. He notices the data fetch runs on every render. What is the correct way to fetch data only once when the component mounts?
  • a) Add [] as the dependency array in useEffect
  • b) Call the API directly in the component body
  • c) Use useMemo instead of useEffect
  • d) Use useCallback

Answer: a) Add [] as the dependency array in useEffect


  1. Ava is using MongoDB to store data and wants to update multiple documents that match a specific condition. Which MongoDB method should she use?
  • a) update
  • b) updateOne
  • c) updateMany
  • d) replaceOne

Answer: c) updateMany


  1. Charlie is working with a large dataset in MongoDB and needs to limit the number of documents returned by a query. Which MongoDB method should he use to achieve this?
  • a) limit
  • b) aggregate
  • c) sort
  • d) group

Answer: a) limit


  1. Ella wants to serve a PWA on her website, so it’s installable on mobile devices. Which file is required to set up a PWA?
  • a) manifest.json
  • b) index.html
  • c) style.css
  • d) app.js

Answer: a) manifest.json


  1. Liam is using Express with middleware to handle request data in JSON format. Where should he place the middleware in his Express app for it to parse JSON?
  • a) Before route definitions
  • b) After route definitions
  • c) Only in error-handling routes
  • d) Inside each route definition

Answer: a) Before route definitions


  1. Emily is using MongoDB and needs to count the number of documents that match certain criteria. Which method should she use?
  • a) countDocuments
  • b) find
  • c) aggregate
  • d) distinct

Answer: a) countDocuments

No comments:

Post a Comment

TCS Wings 1 T1 MERN - Set 10

Rahul Vijayan Follow for more updates TCS Wings 1 T1 MERN - Set 10 Noah is adding a custom middleware to check for a user’s role before acce...