React JS Quiz Questions and Answers

What will be the output of the following JavaScript code: extend?

const obj1 = { a: 10, b: 15, c: 18 };

const obj2 = Object.assign({c: 7, d: 1}, obj1);

console.log(obj2.c, obj2.d);

Answer :
  • 7,1

Explanation :

The Object.assign() method is used to copy the properties and values of one object to another. Objects are assigned and copied by reference.

Do browsers understand JSX code?

Answer :
  • FALSE

Explanation :

No, browsers can't understand JSX code. You need a transpiler to convert your JSX to regular Javascript that browsers can understand. 

How do you write an inline style specifying the font-size:12px and color:red; in JSX?

Answer :
  • style={{fontSize:'12px',color:'red'}}

Explanation :

Inline styles in React should be specified in JSON format, with the keys following camelCase notation.

What happens when the following render() method executes?

render(){

let langs = [ "Ruby ", "ES6 ", "Scala "]

return (

< div > {langs.map(it = > < p >{it}< /p >)} < /div >

)

}

Answer :
  • Displays the list of languages in the array

Explanation :

map is just another method call on a collection. Works perfectly fine

What are the two ways that data gets handled in React?

Answer :
  • state & props

Explanation :

state and props are used to handle data in React.

What is used in ReactJS to increase performance?

Answer :
  • Virtual DOM

Explanation :

Correct

Props in react can________.

Answer :
  • Not be changed in the component

How many elements does a React component return?

Answer :
  • 1 Element

How many stages are there in React JS's life cycle?

Answer :
  • 3