wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

ReactJS Online Test

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

What is the correct command to create a new React project?

a)

npx create-react-app myReactApp  

b)

npm create-react-app

c)

npx create-react-app

d)

npm create-react-app myReactApp

2.

What does myReactApp refer to in the following command?

"npx create-react-app myReactApp"

a)

A reference to an existing app

b)

The name you want to use for the new app  

c)

The directory to create the new app in

d)

The type of app to create

3.

What command is used to start the React local development server?

a)

npm serve

b)

npm run dev

c)

npm start  

d)

npm build

4.

What is the default local host port that a React development server uses?

a)

8080

b)

5000

c)

3000

d)

3500

5.

To develop and run React code, Node.js is required.

a)

True  

b)

False

6.

What type of element will be rendered from the following code?

a)

div

b)

Component

c)

ReactDom

d)

h1

7.

What is the children prop?

a)

A property that lets you nest components in other components  

b)

A property that adds child values to state

c)

A property that lets you set an object as a property

d)

A property that lets you pass data to child components

8.

Which keyword creates a constant in JavaScript?

a)

const  

b)

constant

c)

var

d)

let

9.

A copy of the 'real' DOM that is kept in memory is called what?

a)

React DOM

b)

Shadow DOM

c)

DOM

d)

Virtual DOM  

10.

React component names must begin with an uppercase letter.

a)

True

b)

False

11.

Which operator can be used to conditionally render a React component?

a)

::

b)

??

c)

||

d)

&&  

12.

When rendering a list using the JavaScript map() method, what is required for each element rendered?

a)

data

b)

index

c)

id

d)

key

13.

What tool does React use to compile JSX?

a)

Babel

b)

JSX Compiler

c)

React Router

d)

ReactDOM

14.

How can you optimize performance for a function component that always renders the same way?

a)

Use the useMemo Hook.

b)

Use the shouldComponentUpdate lifecycle method.

c)

Use the useReducer Hook.

d)

Wrap it in the React.memo higher-order component.  

15.

What props will be available to the following component?

"<Car {...props} />"

a)

only static ones

b)

only updated ones

c)

children

d)

all of them  

16.

What is a common use case for ref?

a)

To directly access a DOM node  

b)

To bind the function

c)

To refer to a function

d)

To refer to another JavaScript file

17.

How can you combine the following arrays using the spread operator?

const array1 = [1, 2, 3];
const array2 = [4, 5, 6];

a)

const combined = ...array1 + ...array2;

b)

const combined = [array1, array2];

c)

const combined = [...array1, ...array2];  

d)

const combined = array1 + array2;

18.

React can only render elements in the root document element.

a)

False  

b)

True

19.

What is the correct syntax to import a Component from React?

a)

import React.Component from 'react'

b)

import Component from 'react'

c)

import { Component } from 'react'  

d)

import [ Component ] from 'react'

20.

Find the bug in this code:

a)

Remove the return statement

b)

The first letter of the function must be capitalized  

c)

Add parenthesis around the return value

d)

Wrap the return in a fragment

21.

React separates the user interface into components. How are components combinded to create a user interface?

a)

With webpack

b)

By nesting components  

c)

With code splitting

d)

By putting them in a folder structure

22.

Although React Hooks generally replace class components, there are no plans to remove classes from React.

a)

False

b)

True

23.

Which of the following is NOT a rule for React Hooks?

a)

Hooks cannot be conditional

b)

Hooks can be called in Class or Function components  

c)

Hooks can only be called inside React Function components

d)

Hooks can only be called at the top level of a component

24.

What is the output of the following code?

const make = 'Ford';
const model = 'Mustang';
const car = { make, model };
console.log(car);

a)

{car: 'Ford', car: 'Mustang'}}

b)

{make: 'Ford', model: 'Mustang'}  

c)

{{make: 'Ford', model: 'Mustang'}}

d)

{car: {make: 'Ford', model: 'Mustang'}}

25.

Why should you avoid copying the values of props into a component's state?

a)

Because you should never mutate state

b)

Because you want to allow data to flow back up to the parent

c)

Because that would create two instances of the same state that could become out of sync  

d)

Because prop values cannot be stored in state