React JS MCQ (Multiple Choice Questions)

This set of Multiple Choice Questions & Answers (MCQs) focuses on “React JS”.

1. What is React.js?
a) Open-source JavaScript back-end library
b) JavaScript front-end library to create a database
c) Free and open-source JavaScript front-end library
d) None of the mentioned
View Answer

Answer: c
Explanation: React.js is a free and open-source JavaScript front-end library for creating user interfaces and UI components. It’s also referred to as React or ReactJS.

2. Which of the following acts as the input of a class-based component?
a) Class
b) Props
c) Factory
d) None of the mentioned
View Answer

Answer: b
Explanation: React allows users to pass information to a Component using props. Props are kind of global variable or object.

3. React.js is written in which of the following language?
a) C
b) C++
c) JavaScript
d) Java
View Answer

Answer: c
Explanation: React Native is built on a JavaScript based React.js framework. This is a significant benefit, given that JavaScript is such a widely used language.
advertisement
advertisement

4. How many elements can a valid react component return?
a) React doesn’t return element
b) 1 Element
c) More than 1 element
d) None of the mentioned
View Answer

Answer: b
Explanation: A valid react component can return only one element.

5. In which of the following directory React Components are saved?
a) Inside js/components/
b) Inside components/js/
c) Inside vendor/js/components/
d) Inside vendor/components/
View Answer

Answer: a
Explanation: Inside js/components/ directory React Components are saved.

6. Which of the following command is used to Install create-react-app?
a) npm install create-react-app
b) npm install -f create-react-app
c) npm install -g create-react-app
d) install -g create-react-app
View Answer

Answer: c
Explanation: The “npm install -g create-react-app” command is used to install the create-react-app.

7. In which condition is the React.js Lifecycle method static getDerivedSateFromProps(props, state) is called?
a) When the state of the component is updated
b) When a component is created for the first time
c) Both of the mentioned
d) None of the mentioned
View Answer

Answer: c
Explanation: In React. js, the static getDerivedSateFromProps(props, state) is called in both the cases when a component is created and when a component is updated.
advertisement

8. Which of the following is method is not a part of ReactDOM?
a) ReactDOM.hydrate()
b) ReactDOM.destroy()
c) ReactDOM.createPortal()
d) All of the mentioned
View Answer

Answer: b
Explanation: ReactDOM.destroy() method is not a part of ReactDOM. ReactDOM provides the developers with an API containing the methods such as render(), findDOMNode(), unmountComponentAtNode(), hydrate(), and createPortal().

9. Which of the following is correct about prop in react?
a) Can be changed inside another component
b) Can be changed inside the component
c) Cannot be changed in the component
d) All of the mentioned
View Answer

Answer: c
Explanation: Props cannot be changed, they are immutable. A prop is a special keyword, that stands for properties.
advertisement

10. Which of the following is used to pass data to a component from outside in React?
a) props
b) render with arguments
c) setState
d) PropTypes
View Answer

Answer: a
Explanation: Props can be used to pass dynamic data to a component. When the data in the props changes, the component re-renders.

Sanfoundry Global Education & Learning Series – Javascript Programming.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.