Rahul Vijayan
Follow for more updates
TCS Wings 1 T1 MERN - Set 2
- 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
- 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' }))
- 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
- 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 inuseEffect
?
- a)
useEffect(() => {}, [])
- b)
useEffect(() => { fetchData(); }, [userId])
- c)
useEffect(() => { fetchData(); }, [fetchData])
- d)
useEffect(fetchData, [userId])
Answer: b) useEffect(() => { fetchData(); }, [userId])
- 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
- 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.
- 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
- 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
- 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
- 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
No comments:
Post a Comment