wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

React-Test

Total questions: 115

Worksheet time: 49mins

Name
Class
Date
1.

Which of the following is not a disadvantage of React.js?

a)

React.js has only a view layer. We have put your code for Ajax requests, events and so on

b)

The library of React.js is pretty large

c)
  1. The JSX in React.js makes code easy to read and write.

d)
  1. The learning curve can be steep in React.js.

2.

What is the main advantage of using React.js?

a)

React.js has only a view layer. We have put your code for Ajax requests, events and so on

b)

The library of React.js is pretty large

c)

  1. The JSX in React.js makes code easy to read and write.

d)

  1. React.js allows for easy component reusability and modularity.

3.

Which feature of React.js helps in improving code readability?

a)

React.js has only a view layer. We have put your code for Ajax requests, events and so on

b)

The library of React.js is pretty large

c)

  1. The JSX in React.js makes code easy to read and write.

d)

  1. React.js allows for easy component reusability and modularity.

4.

What is a potential challenge when learning React.js?

a)

React.js has only a view layer. We have put your code for Ajax requests, events and so on

b)

The library of React.js is pretty large

c)

  1. The JSX in React.js makes code easy to read and write.

d)

  1. The learning curve can be steep in React.js.

5.

Does React.js create a VIRTUAL DOM in the memory?

a)
  1. TRUE

b)

FALSE

c)
  1. Can be true or false

d)
  1. Cannot say

6.

What is the purpose of JSX in React.js?

a)

To make code more difficult to read and write

b)

To handle Ajax requests and events

c)

To improve code readability and maintainability

d)

To increase the library size

7.

Which statement best describes the learning curve of React.js?

a)

It is very easy to learn with minimal effort

b)

It has a steep learning curve initially

c)

There is no learning curve at all

d)

It is impossible to learn React.js

8.

How does React.js facilitate component reusability?

a)

By making components difficult to reuse

b)

By limiting the number of components that can be created

c)

By allowing easy creation and reuse of components

d)

By removing the concept of components altogether

9.

What are the two ways to handle data in React?

a)
  1. State & Props

b)
  1. Services & Components

c)
  1. State & Services

d)
  1. State & Component


10.

What is the significance of the virtual DOM in React.js?

a)

It helps in improving code readability

b)

It speeds up the rendering process

c)

It increases the library size

d)

It has no impact on React.js

11.

How does React.js handle data flow between components?

a)

By using only state for data management

b)

By passing data through props

c)

By directly modifying the DOM elements

d)

By creating a separate data layer

12.

What role does the 'key' attribute play in React.js?

a)

It is used to uniquely identify components in lists

b)

It determines the color scheme of the UI

c)

It controls the state of the components

d)

It is not a valid attribute in React.js

13.

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

14.

What describes the ReactJS?

a)

Server Side Framework

b)

Client Side Framework

c)

Both A & B

d)


None of these

15.

ReactJS written in which language?

a)

PHP

b)

JAVASCRIPT

c)

JAVA

d)

NONE OF THIS

16.

What is the purpose of React state?

a)

To store static data

b)

To store styles

c)

To store dynamic data

d)

o store function

17.

What is the use of React hooks?

a)

To manage state and side effects in functional components

b)


To manage styles in functional components

c)

To manage state and side effects in class components

d)

To manage styles in class components

18.

What is the purpose of useEffect hook in React?

a)


To add event listeners

b)


To perform side effects

c)

To render components

d)


To manage state

19.

What is the purpose of useState hook in React?

a)

To manage state in functional components

b)


To manage side effects in functional components

c)


To manage state in class components

d)

To manage side effects in class components

20.

What is the purpose of Higher Order Components (HOCs) in React?

a)

To share data between components

b)

To reuse component logic

c)


To manage component styles

d)

To manage component events

21.

What is the difference between state and props in React?

a)

Props are mutable, state is immutable

b)


Both state and props are mutable

c)


Both state and props are immutable

d)

State is mutable, props are immutable

22.

What is React state used for?

a)

To manage external data sources.

b)

To manage global application data.

c)

To handle routing in React applications.

d)

To store and manage component-specific data that can change over time.

23.

Which hook is commonly used for managing state in functional components in React?

a)

useEffect

b)

useState

c)

useContext

d)

useRef

24.

In a React component, how do you access and modify state?

a)

Using the state property and setState method.

b)

By directly modifying the state variable.

c)

State cannot be accessed or modified in class components.

d)

Using the props property.

25.

What is the purpose of the setState function in React?

a)

To retrieve the current state.

b)

To delete the state.

c)

To set a new state value.

d)

To create a state variable.

26.

How do you initialize a state variable called count with an initial value of 0?

a)

const [count, setCount] = useState(0);

b)

const count = 0;

c)

const count = useState(0);

d)

const count = setState(0);

const setCount = setState(0);

27.

React.Js is a __________?

a)

Framework

b)

Library

c)

None of these.

28.

Which concept includes OOP's?

a)

Functional Components

b)

Class Components

29.

React.Js was created by ___________?

a)

Google

b)

Microsoft

c)

Facebook

30.

What was the Output?

const [data , setData] = useState("Alex");

console.log(data);

a)

data

b)

data Alex

c)

Alex

31.

React is for building _________

a)

Connectivity

b)

User Interface

c)

Database

32.

Will useEffect affect other data?

a)

True

b)

False

33.

Which is the correct syntax?

a)

onclick

b)

Onclick

c)

onClick

d)

OnClick

34.

What is React.Js used for?

a)

Server-Side

b)

Client-Side

c)

For Both

35.

Axios is an __________?

a)

Framework

b)

Library

c)

Package

d)

All These Above

36.

Is React.JS is paid?

a)

Yes

b)

No

37.

What is JSX?

a)

A combination of JavaScript and XML

b)

A new version of JavaScript

c)

The output of a React project

38.

Why would you use JSX to create a React application?

a)

JSX is the only supported method for creating React applications.

b)

JSX allows for good code management. It injects the necessary logic with your HTML.

c)

JSX is supported by all browsers.

39.

What is the purpose of a bundler in web development?

a)

To generate JSX

b)

To convert JSX and other resources into JavaScript

c)

To bootstrap an application

40.

React is a

a)

Full-stack framework

b)

Front-end library

c)

CSS framework

41.

React is created by

a)

Google

b)

Microsoft

c)

Meta

42.

How many elements a valid react component can return?

a)

2

b)

1

c)

4

d)

Unlimited

43.

Browsers natively support JSX.

a)

True

b)

False

44.

Which syntax is used to display dynamic data?

a)

Chocobars

b)

Menubars

c)

Handlebars

45.

What do you call the message wrapped in curly braces below?

let message = 'Hi there';

const element = <p>{message}</p>;

a)

 A JS function

b)

A JS element

c)

A JSX wrapper

d)

A JS expression

46.

Which of the following is not a disadvantage of React.js?

a)

React.js has only a view layer. We have put your code for Ajax requests, events and so on.

b)

The library of React.js is pretty large.

c)

The JSX in React.js makes code easy to read and write.

d)

The learning curve can be steep in React.js.

47.

What would be the output of the following example?

var Helloworld=(props)=>  {  

 return(  

 <div>  

 Hello World 1  

 </div>  

 <div>  

 Hello World 2  

 </div>  

 );  

}  

ReactDOM.render(<Helloworld/>,mountNode)  

a)

Hello World 1

b)

Hello World 2

c)

Hello World 1 Hello World 2

d)

Error

48.

Which of the following is used to pass data to a component from outside in React.js?

a)

 SetState

b)

Render with arguments

c)

Props

d)

 PropTypes

49.

What does ES6 stand for?

a)

 ECMAScript 6

b)

ECMA 6

c)

ECMAJavaScript 6

d)

EJavaScript 6

50.

What is Babel?

a)

 A JavaScript transpiler

b)

A JavaScript interpreter

c)

 A JavaScript Compiler

d)

 None of the above

51.

React is used mainly for building ........

a)

Database

b)

User interface

c)

Connectivity

d)

Design platform

52.

Which function is used to change the state of react component?

a)

this.State{}

b)

 this.setState

c)

this.setChangeState

d)

 None of the Above

53.

What do you call the message wrapped in curly braces below?

let message = 'Hi there';

const element = <p>{message}</p>;

a)

A JS function

b)

A JS element

c)

 A JSX wrapper

d)

A JS expression

54.

What will be logged in the console after this code runs?


const [count, setCount] = useState<number>(0);

setCount(5);

console.log(count);

a)

5

b)

0

c)

undifined

d)

Error

55.

Which is the correct way to update a boolean state?
const [isOpen, setIsOpen] = useState<boolean>(false);

a)

setIsOpen(true)

b)

setIsOpen = true

c)

isOpen = true

d)

setIsOpen(false = true)

56.

What is the best way to update state based on a previous state?


const [count, setCount] = useState<number>(0);

a)

setCount(count + 1)

b)

setCount(prev => prev + 1)

c)

count++

d)

setCount = count + 1

57.

What will this render initially?

const [title, setTitle] = useState<string | null>(null);

return <h1>{title ?? "Default Title"}</h1>;

a)

null

b)

"title"

c)

"Default Title"

d)

Undifined

58.

What will be the value of input after this function?

const [input, setInput] = useState<string>("");

const handleChange = () => {

setInput("Updated");

};

a)

""

b)

"Updated"

c)

undefined

d)

null

59.

What is the primary purpose of useEffect in React?

a)

To create state variables

b)

To fetch and manage props

c)

To handle side effects in functional components

d)

To update the DOM manually

60.

useEffect(() => {

console.log("Hello");

}, []);

a)

Run on every render

b)

Never run

c)

Run once after initial render

d)

Run only when a button is clicked

61.

When does useEffect run if no dependency array is provided?

useEffect(() => {

console.log("Effect");

});

a)

Only once

b)

Never

c)

After every render

d)

Only after state changes

62.

What will be the output of this code?

const [count, setCount] = useState(0);

useEffect(() => {

console.log("Count changed");

}, [count]);

a)

Logs only on initial render

b)

Logs every time count changes

c)

Never logs

d)

Logs once then never again

63.

Which best describes this behavior?

useEffect(() => {

console.log("Component mounted");

}, []);

a)

Mount and update

b)

Update only

c)

Mount only

d)

Unmount only

64.

Which import is correct for using useEffect?

a)

import { useEffect } from 'vite'

b)

import { useEffect } from 'vite'

c)

import { useEffect } from 'vite'

d)

import { useEffect } from 'vite'

65.

What is the type of the cleanup function in useEffect?

a)

() => string

b)

() => void

c)

number

d)

boolean

66.

What is the main purpose of useContext in React?

a)

Managing local component state

b)

Sharing data globally across components

c)

Handling side effects

d)

Styling components

67.

What is the correct import for useContext?

a)

import { useContext } from 'vite'

b)

import useContext from 'react'

c)

import { useContext } from 'react'

d)

import useContext from 'vite-react'

68.

What must be passed into useContext()?

a)

A reducer

b)

A state setter

c)

A context object

d)

A JSX element

69.

What will be printed to the console?

const MyContext = React.createContext("default");

const Child = () => {

const value = useContext(MyContext);

console.log(value);

return null;

};

<MyContext.Provider value="custom">

<Child />

</MyContext.Provider>

a)

"default"

b)

"custom"

c)

undefined

d)

null

70.

How many times does a component re-render when the context value changes?

a)

Never

b)

Once per prop change

c)

Once per context value change

d)

Infinite times

71.

In React with TypeScript, what is the primary purpose of useReducer?

a)

To replace useEffect

b)

To manage complex state logic in a predictable way

c)

To improve rendering speed

d)

To handle routing

72.

Which of the following is the correct TypeScript syntax for declaring useReducer?

a)

const [state, dispatch] = useReducer(reducer, initialState)

b)

const [state, dispatch] = useReducer<StateType, ActionType>(reducer, initialState)

c)

const state = useReducer(reducer, initialState)

d)

useReducer(reducer, state)

73.

In a TypeScript useReducer, what type is dispatch?

a)

(action: ActionType) => void

b)

(state: StateType) => void

c)

(action: any) => any

d)

Function

74.

Which hook is best suited for state logic involving multiple sub-values and complex updates?

a)

useState

b)

useEffect

c)

useReducer

d)

useDemo

75.

In React + TypeScript, which is the correct way to define an action union type?

a)

type Action = { type: 'ADD' } | { type: 'REMOVE', payload: number };

b)

interface Action { type: string; }

c)

type Action = { type: string; payload: any };

d)

Action = { type: 'ADD' };

76.

When using TypeScript with useReducer, what does the generic <S, A> represent?

a)

S = State type, A = Action type

b)

S = String type, A = Array type

c)

S = Source type, A = Action type

d)

S = State value, A = Async handler

77.

What is the main purpose of the useRef hook in React?

a)

To store mutable values that persist across renders

b)

To trigger component re-renders

c)

To handle asynchronous code

d)

To store state history

78.

What type of object does useRef return?

a)

{ current: T }

b)

{ value: T }

c)

T directly

d)

RefObject<T> without current

79.

What is the main purpose of useMemo in React?

a)

To store mutable values between renders

b)

To memoize computed values to avoid unnecessary recalculations

c)

To trigger component re-renders

d)

To store DOM references

80.

What is the first argument passed to useMemo?

a)

A dependency array

b)

A callback function returning the computed value

c)

An initial value

d)

A reducer function

81.

What is the second argument of useMemo?

a)

The initial value

b)

The dependency array

c)

The state variable

d)

The reducer

82.

Which is true about useMemo and performance?

a)

Which is true about useMemo and performance?

b)

It can cause unnecessary overhead if overused

c)

It is required for all calculations

d)

It is faster than plain variables

83.

What is the main purpose of React.memo?

a)

To memoize functions

b)

To memoize component rendering and avoid unnecessary re-renders

c)

To store mutable state

d)

To optimize API calls

84.

What is the correct TypeScript syntax to wrap a component with React.memo?

a)

export default React.memo(MyComponent);

b)

export default memo(MyComponent);

c)

export default MyComponent.memo();

d)

export default React.useMemo(MyComponent);

85.

How can you prevent unnecessary re-renders if props are objects?

a)

Use useRef

b)

Use useCallback / useMemo to memoize the object or function props

c)

Use React.StrictMode

d)

Use a reducer

86.

Which hook works well with React.memo to keep function props stable?

a)

useState

b)

useEffect

c)

useCallback

d)

useReducer

87.

What is the primary purpose of useCallback?

a)

To memoize values

b)

To memoize functions so they don’t get re-created unnecessarily

c)

To store mutable values

d)

To trigger re-renders

88.

Which is the correct syntax for useCallback?

a)

useCallback(fn, deps)

b)

useCallback(deps, fn)

c)

useCallback(() => fn, deps)

d)

useCallback(fn)

89.

What is the main benefit of useCallback when passing callbacks to deeply nested components?

a)

It increases state updates speed

b)

It keeps function references stable, reducing unnecessary renders

c)

It prevents memory leaks

d)

It automatically caches results

90.

Which hook is best for memoizing expensive calculations:

a)

useCallback

b)

useMemo

c)

React.memo

d)

useReducer

91.

JSX is necessary to work with React.js?

a)

True

b)

False

92.

React is mainly for building ___

a)

Database

b)

Connectivity

c)

User interface

d)

Design Platform

93.

Which is used to keep the value of components unique?

a)

Ref

b)

Key

c)

store

d)

Data

94.
a)

useEffect(() => { setDone(true); });

b)

useEffect(() => { setDone(true); }, []);

c)

useEffect(() => { setDone(true); }, [setDone]);

d)

useEffect(() => { setDone(true); }, [done, setDone]);

95.
a)

Remove this

b)

Capitalize clock

c)

Remove the render method

d)

Add quotes around the return value

96.

Why might you use a ref?

a)

to directly access the DOM node

b)

to refer to another JS file

c)

to bind the function

d)

to call a function

97.
a)

{{name: "Venkat", age: 30}}

b)

{name: "Venkat", age: 30}

c)

{person: "Venkat", person: 30}}

d)

{person: {name: "Venkat", age: 30}}

98.
a)

Error. Cannot use direct JavaScript code in JSX

b)

Error. Should be replaced with a for..loop for correct output

c)

Displays the list of languages in the array

d)

Displays nothing

99.

What does this React element look like given the following function?

React.createElement('h1', null, "What's happening?");

a)

<h1 props={null}>What's happening?</h1>

b)

<h1>What's happening?</h1>

c)

<h1 id="component">What's happening?</h1>

d)

<h1 id="element">What's happening?</h1>

100.

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

a)

style={{font-size:12,color:'red'}}

b)

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

c)

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

d)

style={{font-size:12px,color:'red'}}

101.

What does npm stand for?

a)

Node Project Manager

b)

Node Program Manager

c)

Node Package Manager

d)

Network Package Manager

102.

What is the primary purpose of npx?

a)

To manage Node.js versions.

b)

To create new Node.js projects.

c)

The primary purpose of npx is to execute Node.js packages without global installation.

d)

To install Node.js packages globally.

103.

What is JSX commonly used for?

a)

JSX is used for styling CSS files.

b)

JSX is commonly used for building user interfaces in React.

c)

JSX is primarily used for database management.

d)

JSX is a programming language for backend development.

104.

How do props function in React?

a)

Props are only for rendering static content in React.

b)

Props are used to style components in React.

c)

Props function as a mechanism for passing data and event handlers to React components.

d)

Props are a type of state management in React.

105.

What is the role of nvm in Node.js development?

a)

nvm is a framework for building Node.js applications.

b)

nvm is used to compile Node.js from source code.

c)

nvm is a package manager for Node.js libraries.

d)

nvm is used to manage multiple Node.js versions in development.

106.

Can you install packages globally using npm?

a)

You can only install packages globally with yarn.

b)

Yes, you can install packages globally using npm.

c)

Global installation is not supported by npm.

d)

No, npm only allows local installations.

107.

What is the difference between npm install and npx?

a)

npm install installs packages; npx runs packages without installing them globally.

b)

npm install is used for running scripts; npx is for managing dependencies.

c)

npm install runs packages without installing them; npx installs packages locally.

d)

npm install updates existing packages; npx installs packages globally.

108.

How do you pass props to a child component in React?

a)

Pass props using a global state management library.

b)

Use CSS to style the child component.

c)

Use JSX syntax to pass props, e.g., .

d)

Directly modify the child component's code to include props.

109.

What file extension is typically used for JSX files?

a)

.jsx

b)

.js

c)

jsx

d)

.html

110.

What command would you use to create a new React app using npx?

a)

npx create-app my-app

b)

npx react-app my-app

c)

npm create-react-app my-app

d)

npx create-react-app my-app

111.

What is the significance of the package.json file in a project?

a)

It is used for writing server-side code in Python.

b)

It serves as a database for project files.

c)

The package.json file is significant for managing project dependencies and configurations in a Node.js project.

d)

The package.json file is only for storing user information.

112.

How can you switch Node.js versions using nvm?

a)

Run 'nvm set ' to select a Node.js version.

b)

Use 'nvm switch ' to change Node.js versions.

c)

Use 'nvm use ' to switch Node.js versions.

d)

Execute 'nvm change ' to update Node.js version.

113.

What is a common use case for using JSX in a project?

a)

Creating user interfaces in React applications.

b)

Building server-side applications

c)

Designing static websites with HTML

d)

Creating mobile apps with Flutter

114.

How do you update a package using npm?

a)

Run 'npm upgrade ' to refresh a package.

b)

Execute 'npm refresh ' to get the latest version.

c)

Use 'npm install ' to update a package.

d)

Use 'npm update ' to update a specific package.

115.

What is the command to uninstall a package using npm?

a)

npm delete

b)

npm purge

c)

npm remove

d)

npm uninstall