Monday, October 28, 2024

TCS Wings 1 T1 MERN - Set 3

Rahul Vijayan
Follow for more updates

TCS Wings 1 T1 MERN - Set 3 


  1. Ethan is working with MongoDB and needs to perform an aggregation to calculate the average price of products in each category. Which MongoDB pipeline stage should he use?
  • a) $group
  • b) $match
  • c) $sort
  • d) $project

Answer: a) $group


  1. Amelia has created a form in her React app to add new items to her MongoDB collection through an Express API. Which HTTP method should she use for this request?
  • a) GET
  • b) POST
  • c) PUT
  • d) DELETE

Answer: b) POST


  1. Lucas wants to prevent his React component from re-rendering when a prop changes. Which hook should he use to memoize the component to prevent unnecessary renders?
  • a) useEffect
  • b) useCallback
  • c) useMemo
  • d) React.memo

Answer: d) React.memo


  1. Mia is designing a MongoDB query to find all products with a price greater than $100. Which operator will help her achieve this?
  • a) $lt
  • b) $gt
  • c) $ne
  • d) $in

Answer: b) $gt


  1. Liam has a PWA and wants it to load as a fullscreen app when launched from the home screen on mobile. Which attribute in the manifest.json file will help him achieve this?
  • a) display
  • b) theme_color
  • c) background_color
  • d) orientation

Answer: a) display


  1. Sofia is optimizing her Express app by adding middleware for logging. Which popular middleware package can she use for this purpose?
  • a) morgan
  • b) body-parser
  • c) cors
  • d) helmet

Answer: a) morgan


  1. Ryan wants to ensure his MongoDB collections are accessible only to authenticated users in his Express app. Which middleware is best suited to protect routes requiring authentication?
  • a) Logging middleware
  • b) Authorization middleware
  • c) Error-handling middleware
  • d) Static middleware

Answer: b) Authorization middleware


  1. Harper is implementing a feature in her React app that updates based on a prop change. Which hook will allow her to respond to the prop change in a controlled way?
  • a) useState
  • b) useEffect
  • c) useCallback
  • d) useMemo

Answer: b) useEffect


  1. Noah is building a Node.js app and wants to handle JSON data in incoming requests. Which Express middleware should he add?
  • a) express.static
  • b) express.json
  • c) express.urlencoded
  • d) body-parser

Answer: b) express.json


  1. Ava has an API call in her React component and wants to avoid rendering it twice when the component mounts. Which dependency array setup should she use in useEffect?
  • a) []
  • b) [props]
  • c) [state]
  • d) useEffect without array

Answer: a) []

TCS Wings 1 T1 MERN - Set 2

Rahul Vijayan
Follow for more updates


TCS Wings 1 T1 MERN - Set 2 

  1. Leo is developing a Node.js API and needs to handle large JSON payloads. Which middleware should he add to his Express app?
  • a) express.static
  • b) express.urlencoded
  • c) express.json
  • d) body-parser

Answer: c) express.json


  1. Emily is using useState in her React component to handle form data. Which statement correctly updates the state without mutating the existing state object?
  • a) setState({ name: 'Emily' })
  • b) setState((prevState) => ({ ...prevState, name: 'Emily' }))
  • c) setState = { name: 'Emily' }
  • d) setState(name: 'Emily')

Answer: b) setState((prevState) => ({ ...prevState, name: 'Emily' }))


  1. Arjun is building a feature to allow users to update their profiles. Which HTTP method should he use for this operation in his Express app?
  • a) GET
  • b) POST
  • c) PUT
  • d) DELETE

Answer: c) PUT


  1. Sara is building a component that fetches and displays a user’s profile. She wants the component to refetch data every time the userId prop changes. Which setup should she use in useEffect?
  • a) useEffect(() => {}, [])
  • b) useEffect(() => { fetchData(); }, [userId])
  • c) useEffect(() => { fetchData(); }, [fetchData])
  • d) useEffect(fetchData, [userId])

Answer: b) useEffect(() => { fetchData(); }, [userId])


  1. Ben wants to aggregate and group documents in MongoDB by a specific field. Which MongoDB method will help him achieve this?
  • a) find
  • b) sort
  • c) aggregate
  • d) mapReduce

Answer: c) aggregate


  1. Emma is designing a React component that updates its style dynamically based on state. Which method is the most React-appropriate way to apply styles conditionally?
  • a) Use inline styles with a ternary operator.
  • b) Use an if-else statement directly in the JSX.
  • c) Use a CSS file with conditional class names.
  • d) Write CSS styles in a separate JavaScript function.

Answer: a) Use inline styles with a ternary operator.


  1. Jordan is trying to make his Node.js application scale well. What strategy could he use to handle high traffic efficiently?
  • a) Increase the number of GET requests
  • b) Use clustering or worker threads to handle multiple requests simultaneously
  • c) Increase the memory available to the Node.js application
  • d) Rewrite the code in another language

Answer: b) Use clustering or worker threads to handle multiple requests simultaneously


  1. Lisa wants to ensure that her Express app has a global error handler. Which middleware placement will ensure this?
  • a) At the beginning of her middleware stack
  • b) Just after defining all routes
  • c) Inside the router
  • d) Inside each route handler

Answer: b) Just after defining all routes


  1. Martin has a React app that interacts with a Node.js backend. He wants to handle failed API requests due to network errors. Which approach should he take?
  • a) Log the error to the console
  • b) Use a try-catch block with Axios requests
  • c) Add retries for each Axios request
  • d) Refresh the page after each error

Answer: b) Use a try-catch block with Axios requests


  1. Olivia is designing an Express app with user authentication. Which middleware will help her protect routes from unauthorized access?
  • a) Static middleware
  • b) Logging middleware
  • c) Authentication middleware
  • d) Error-handling middleware

Answer: c) Authentication middleware

TCS Wings 1 T1 MERN - Set 1

Rahul Vijayan
Follow for more updates


TCS Wings 1 T1 MERN - Set 1

  1. James is working on a React application. He notices that after a certain update, the state isn't updating as expected when using the useState hook. Which of the following is the most likely cause?
    • a) James is not updating the state directly in the component function.
    • b) James is mutating the state directly instead of using the setter function returned by useState.
    • c) James is using useEffect to trigger the state update.
    • d) James is using multiple useState hooks, which are overwriting each other.
    Answer: b) James is mutating the state directly instead of using the setter function returned by useState.

  1. Lily is implementing a function in her React component to fetch data from an API. She wants this to happen only once when the component mounts. Which lifecycle hook should she use to achieve this?
    • a) componentDidUpdate
    • b) useEffect with an empty dependency array
    • c) useState
    • d) componentWillUnmount
    Answer: b) useEffect with an empty dependency array

  1. Sam is building a login form in React and is using Axios to call a REST API endpoint. He’s noticing that the request is sent twice every time he submits the form. What might be the reason?

    • a) Sam is using the useEffect hook incorrectly, causing it to rerun.
    • b) Sam has accidentally called the function twice in the button’s onClick handler.
    • c) Sam’s form is submitting both via onClick and the form’s submit event.
    • d) Sam is not using Axios correctly.

    Answer: c) Sam’s form is submitting both via onClick and the form’s submit event.


  1. Maya wants to add a feature where her Express app logs each incoming request. Which middleware function should she use to achieve this?
    • a) Error-handling middleware
    • b) Route-level middleware
    • c) Application-level middleware
    • d) next() middleware
    Answer: c) Application-level middleware

  1. Adam is working with MongoDB and needs to retrieve documents sorted by a specific field. Which method will help him achieve this?

    • a) sort
    • b) aggregate
    • c) find
    • d) filter

    Answer: a) sort


  1. Priya needs to display a list of items in her React app with sorting and filtering options. Which hook would be most useful to update the UI when sorting criteria change?
    • a) useRef
    • b) useEffect
    • c) useMemo
    • d) useCallback
    Answer: b) useEffect

  1. Ethan wants to optimize his Express app to handle static files efficiently. Which built-in middleware should he use?
    • a) app.use('/static', express.static())
    • b) app.use(express.json())
    • c) app.use(express.urlencoded())
    • d) app.use('/files', express.static())
    Answer: a) app.use('/static', express.static())

  1. Nina is using React components to create a list of user profiles from an API. Which lifecycle hook should she use to fetch the data when the component mounts?

    • a) useLayoutEffect
    • b) useEffect
    • c) useState
    • d) useMemo

    Answer: b) useEffect


  1. Daniel is creating a form that submits data to his Express server. Which HTTP method should he use to submit the data if he wants to create a new resource?
    • a) GET
    • b) POST
    • c) PUT
    • d) DELETE
    Answer: b) POST

  1. Sophia is working on a PWA for offline functionality. Which API should she use to cache assets and data for offline access?
  • a) Fetch API
  • b) Service Worker API
  • c) Local Storage
  • d) Session Storage

Answer: b) Service Worker API

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...