MCQs
Let’s recap the important concepts with MCQs.
1. What is the primary purpose of the useState hook in React?
A. To fetch data from an API
B. To add state to functional components
C. To manipulate the DOM
D. To create class components
Answer: B
2. What does the replace() method do in JavaScript?
A. Removes whitespace from a string
B. Replaces part of a string with another string
C. Splits a string into an array
D. Joins two strings together
Answer: B
3. What is the correct syntax for using replace()?
A. string.replace(newValue, searchValue)
B. replace(string, searchValue, newValue)
C. `string.replace(searchValue, newValue)
D. string.replace(value)
Answer: C
4. Which method would you use to remove spaces at the beginning and end of a string?
A. split()
B. trim()
C. replace()
D. slice()
Answer: B
5. What is returned by the expression " Hello ".trim()?
A. " Hello "
B. "Hello "
C. " Hello"
D. "Hello"
Answer: D


