React Js(Computer Science ) Questions and Answers

Question 1. How do you write an inline style specifying the font-size:12px and color:red; in JSX
  1.    style={{font-size:12,color:'red'}}
  2.    style={{fontSize:'12px',color:'red'}}
  3.    style={fontSize:'12px',color:'red'}
  4.    style={{font-size:12px,color:'red'}}
Explanation:-
Answer: Option C. -> style={fontSize:'12px',color:'red'}

Question 2. Which of the following API is a MUST for every ReactJS component?
  1.    getInitialState
  2.    render
  3.    renderComponent
  4.    None of the above
Explanation:-
Answer: Option B. -> render

Question 3. Which of the following is correct syntax for a button click event handler, foo?
Explanation:-
Answer: Option B. -> render

Question 4. At the highest level, React components have lifecycle events that fall into
  1.    Initialization
  2.    State/Property Updates
  3.    Destruction
  4.    All of these
Explanation:-
Answer: Option D. -> All of these

Question 5. How many elements does a react component return?
  1.    2 Elements
  2.    1 Element
  3.    Multiple Elements
  4.    None of These
Explanation:-
Answer: Option B. -> 1 Element

Question 6. What is a good use case for using a function while rendering a dynamic list of items
  1.    If we need to compute a value based on properties of items in the loop.
  2.    None. Functions should not be used while rendering a dynamic list.
  3.    To make the code shorter
  4.    None of the above
Explanation:-
Answer: Option A. -> If we need to compute a value based on properties of items in the loop.

Question 7. What happens when the following render() method executes?<br /><br /> render(){<br /> let langs = ["Ruby","ES6","Scala"]<br /> return (<div><br /> {langs
  1.    Displays the list of languages in the array
  2.    Error. Cannot use direct JavaScript code in JSX
  3.    Displays nothing
  4.    Error. Should be replaced with a for..loop for correct output
Explanation:-
Answer: Option A. -> Displays the list of languages in the array

Question 8. What is a controlled input element?
  1.    An input element with the controlled flag
  2.    An input element that is controlled by the value of another input element
  3.    An input element that can only accept a list of characters
  4.    An input element whose value is being controlled by a component’s state
Explanation:-
Answer: Option D. -> An input element whose value is being controlled by a component’s state

Question 9. What is the second argument for setState useful for?
  1.    To invoke code after the setState operation is done
  2.    To replace the state completely instead of the default merge action
  3.    To access the previous state before the setState operation
  4.    None of the above
Explanation:-
Answer: Option A. -> To invoke code after the setState operation is done

Question 10. Everything in react is
  1.    Package
  2.    Model
  3.    Method
  4.    Component
Explanation:-
Answer: Option D. -> Component