Unit 1: Refreshing JavaScript and React Fundamentals - Practice Quiz

INT252 — Web App Development With Reactjs 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which arrow function correctly returns the sum of a and b?

Arrow functions Easy
A. (a, b) => a + b
B. function => (a + b)
C. (a, b) = a + b
D. (a, b) -> a + b

2 Which keyword declares a block-scoped variable that cannot be reassigned?

Block-scoped variables using let and const Easy
A. let
B. var
C. static
D. const

3 Which array method creates a new array by transforming every element?

Array iteration and transformation methods Easy
A. find()
B. some()
C. includes()
D. map()

4 Given const user = { name: "Asha", age: 20 };, which statement extracts the name property?

Destructuring assignments Easy
A. const [name] = user;
B. const name => user;
C. const name := user;
D. const { name } = user;

5 Which operator is used for both spread and rest syntax in JavaScript?

Spread and rest operators Easy
A. ...
B. **
C. ??
D. =>

6 Which keyword makes a function or value available to other JavaScript modules?

ES modules Easy
A. require
B. publish
C. export
D. include

7 What does immutability mean when updating React state?

Immutability principles Easy
A. Changing the existing value directly in memory
B. Preventing the component from rendering again
C. Storing every value in a global variable
D. Creating a new value instead of modifying the old one

8 What is a pure function?

Functional programming concepts relevant to React Easy
A. A function that returns predictable output without side effects
B. A function that must be declared with async
C. A function that can only return another function
D. A function that always changes a global variable

9 What does a shallow copy of an object do with its nested objects?

Shallow and deep copying mechanisms Easy
A. It recursively copies every nested object
B. It keeps references to the same nested objects
C. It removes all nested object properties
D. It converts nested objects into strings

10 When are two separate object variables referentially equal using ===?

Referential equality and state comparison Easy
A. When they were created on the same line
B. When they contain properties with equal values
C. When they point to the same object
D. When they use the same property names

11 What is a common characteristic of a Single Page Application (SPA)?

Single Page Applications and Multi Page Applications Easy
A. It stores each component in a separate website
B. It updates views without fully reloading the page
C. It reloads a new HTML document for every action
D. It works without any JavaScript in the browser

12 What does declarative UI mean in React?

React philosophy and declarative UI paradigm Easy
A. Manually changing each DOM element after every event
B. Describing what the UI should look like for the current state
C. Writing browser commands in a fixed execution order
D. Building every screen with separate HTML documents

13 What is a main benefit of component-based architecture?

Component-based architecture Easy
A. It supports reusable and maintainable UI pieces
B. It replaces JavaScript with plain HTML pages
C. It requires all code to remain in one file
D. It prevents data from being passed between views

14 Which command starts the process of creating a new Vite project with npm?

Setting up React applications using Vite Easy
A. npm start vite-project
B. npm build react@latest
C. npm install react-page
D. npm create vite@latest

15 What is the main purpose of a development server in a React project?

Modern React development environment and tooling Easy
A. It stores application data in a remote database
B. It replaces the browser used to display the app
C. It permanently hosts the production app online
D. It serves the app locally and supports fast updates

16 How does a feature-based folder structure organize a React project?

Feature-based project folder structure and best practices Easy
A. It groups files only by their file extensions
B. It groups related files by application feature
C. It stores source code inside dependency folders
D. It places every component in the project root

17 How is a JavaScript expression inserted into JSX?

JSX syntax and expressions Easy
A. By placing it inside curly braces
B. By placing it inside HTML comments
C. By placing it inside square brackets
D. By placing it after a semicolon

18 Which React DOM method creates a root for rendering a React application?

Rendering components into the DOM Easy
A. createElement()
B. appendChild()
C. querySelector()
D. createRoot()

19 What usually happens when a functional component's state changes?

Functional components and render lifecycle Easy
A. React permanently removes the component
B. React calls the component function again
C. The browser reloads the entire website
D. The component becomes a class component

20 What does React do during reconciliation?

Introduction to Virtual DOM and reconciliation process Easy
A. It deletes the entire DOM after each state change
B. It compares UI representations to determine needed updates
C. It converts every component into a database table
D. It downloads a new HTML page from the server

21 Consider the following code:

const team = { name: 'UI', members: ['Ana'], print() { this.members.forEach(member => console.log(this.name + ': ' + member)); } };

Why does calling team.print() correctly log UI: Ana?

Arrow functions Medium
A. The forEach method automatically binds this to team.
B. The arrow callback inherits this from print.
C. The arrow callback searches the global object and creates a permanent this binding for every method.
D. The arrow callback creates a new this for team.

22 What is printed by this code after the timers execute?

for (let i = 0; i < 3; i++) { setTimeout(() => console.log(i), 0); }

Block-scoped variables using let and const Medium
A. 0, 0, and 0
B. A ReferenceError occurs
C. 0, 1, and 2
D. 3, 3, and 3

23 What is the value of result?

const items = [{ name: 'pen', active: true }, { name: 'bag', active: false }, { name: 'book', active: true }];

const result = items.filter(item => item.active).map(item => item.name.toUpperCase());

Array iteration and transformation methods Medium
A. [true, true]
B. ['PEN', 'BAG', 'BOOK']
C. ['PEN', 'BOOK']
D. ['pen', 'book']

24 What does the following code print?

const user = { name: 'Mira', address: { city: 'Pune' } };

const { name: displayName, role = 'viewer', address: { city } } = user;

console.log(displayName + '-' + role + '-' + city);

Destructuring assignments Medium
A. Mira-viewer-undefined
B. undefined-viewer-Pune
C. Mira-viewer-Pune
D. Mira-undefined-Pune

25 What is logged by this code?

const original = { settings: { theme: 'dark' } };

const copy = { ...original };

copy.settings.theme = 'light';

console.log(original.settings.theme, copy.settings.theme);

Spread and rest operators Medium
A. light light
B. dark dark
C. dark light
D. light dark

26 A file named app.js contains export default function App() {} and export const version = '1.0';. Which statement correctly imports both exports?

ES modules Medium
A. import App, { version } from './app.js';
B. import { App as default, version } from './app.js';
C. import { App, version } from './app.js';
D. import * as App, { version } from './app.js';

27 Given state shaped as { name: 'Lee', profile: { city: 'Delhi', timezone: 'IST' } }, which update changes only the city while preserving all other fields and references appropriately?

Immutability principles Medium
A. setUser(prev => { const next = { ...prev }; next.profile.city = 'Goa'; return next; });
B. setUser(prev => ({ ...prev, profile: { ...prev.profile, city: 'Goa' } }));
C. setUser(prev => ({ ...prev, profile: { city: 'Goa' } }));
D. setUser(prev => { prev.profile.city = 'Goa'; return prev; });

28 Which function is pure and therefore easiest to use predictably during React rendering?

Functional programming concepts relevant to React Medium
A. const timestamp = () => Date.now();
B. const visit = user => ++user.views;
C. const fullName = user => user.first + ' ' + user.last;
D. const arrange = items => items.sort();

29 An object contains nested arrays and a Date. Which approach creates an independent deep copy while preserving the Date as a Date in modern browsers?

Shallow and deep copying mechanisms Medium
A. const copy = Object.assign({}, original);
B. const copy = structuredClone(original);
C. const copy = { ...original };
D. const copy = JSON.parse(JSON.stringify(original));

30 Consider an array state update:

const next = current;

next.push('B');

setItems(next);

Which statement best describes the problem?

Referential equality and state comparison Medium
A. Object.is(current, next) is false, so React must rerender.
B. Object.is(current, next) is true, so React may skip the update.
C. React deeply compares every array element before deciding whether to render the complete component tree.
D. push creates a new array, so the update is immutable.

31 A dashboard must update its URL and switch views after initial loading without requesting a new HTML document for each navigation. Which architecture best matches this requirement?

Single Page Applications and Multi Page Applications Medium
A. A static site that reloads every document and reconstructs the complete interface on each navigation
B. An SPA using client-side routing
C. An MPA using server-side page routing
D. An MPA using separate HTML entry files

32 Which implementation most clearly follows React's declarative UI approach for displaying an online status?

React philosophy and declarative UI paradigm Medium
A. document.querySelector('p').textContent = isOnline ? 'Online' : 'Offline';
B. return <p>{isOnline && 'Online'}</p>;
C. return <p>{isOnline ? 'Online' : 'Offline'}</p>;
D. if (isOnline) document.body.innerHTML = '<p>Online</p>';

33 A product card containing an image, title, price, and add button appears on several pages. What is the best component-based design?

Component-based architecture Medium
A. Copy the complete card markup into every page that displays a product.
B. Create one large page component that contains every possible card variant and directly modifies each element.
C. Create a reusable ProductCard that receives product data and an add handler.
D. Store all card markup in App and select it using DOM element IDs.

34 Which command sequence creates and starts a React project using Vite?

Setting up React applications using Vite Medium
A. npm install -g vite react react-dom, then vite create my-app, npm eject, and npm run production-server
B. npm create react-app my-app, then cd my-app, npm install, and npm run vite
C. npm install react-vite my-app, then cd my-app, npm build, and npm start
D. npm create vite@latest my-app -- --template react, then cd my-app, npm install, and npm run dev

35 In a standard Vite React project, which command creates optimized production assets, usually in the dist directory?

Modern React development environment and tooling Medium
A. npm run dev
B. npm run preview
C. npm run lint
D. npm run build

36 An application has checkout-specific components and hooks plus a generic Button used throughout the application. Which organization best follows a feature-based structure?

Feature-based project folder structure and best practices Medium
A. Place every component and hook together in one root-level components directory.
B. Place checkout code in features/checkout and Button in shared/components.
C. Place checkout code in shared and duplicate Button inside every feature.
D. Place all JavaScript files directly inside src and distinguish their purpose only through long filenames.

37 Which JSX expression displays No items when count is 0 and displays 3 items when count is 3?

JSX syntax and expressions Medium
A. <span>{count ? count + ' items' : 'No items'}</span>
B. <span>{count || 'No items'}</span>
C. <span>{count && count + ' items'}</span>
D. <span>{if (count) count + ' items'}</span>

38 Assuming createRoot is imported from react-dom/client, which code correctly mounts App into <div id='root'></div>?

Rendering components into the DOM Medium
A. document.getElementById('root').render(createRoot(<App />));
B. createRoot(document.getElementById('root')).render(<App />);
C. createRoot(<App />).render(document.getElementById('root'));
D. createRoot(document.querySelector('App')).mount(<div id='root' />);

39 A functional component receives userId as a prop and should load user data after the component is committed whenever userId changes. Which implementation is appropriate?

Functional components and render lifecycle Medium
A. useEffect(() => { loadUser(userId); }, []);
B. useEffect(() => { loadUser(userId); }, [userId]);
C. useEffect(() => { loadUser(userId); });
D. loadUser(userId); return <Profile />;

40 A rendered list can be reordered and its items have stable database IDs. Which key best helps React reconcile the list while preserving the correct item state?

Introduction to Virtual DOM and reconciliation process Medium
A. <Row key={index} item={item} />
B. <Row key={item.id} item={item} />
C. <Row key={item.name + Date.now()} item={item} />
D. <Row key={Math.random()} item={item} />

41 What does the following code print?

const obj = { value: 10, make() { const arrow = () => this.value; return { value: 20, arrow }; } }; const { arrow } = obj.make(); console.log(arrow.call({ value: 30 }));

Arrow functions Hard
A. 20
B. undefined
C. 30
D. 10

42 What happens when this code executes?

let value = 1; { console.log(typeof value); let value = 2; }

Block-scoped variables using let and const Hard
A. It logs number and then changes the outer value to 2.
B. It throws a ReferenceError before logging anything.
C. It logs number because the outer variable is visible.
D. It logs undefined because typeof safely handles every inaccessible binding.

43 Given const a = [, 1, , 2]; const b = a.map(x => x * 2); const c = a.filter(() => true);, which description is correct?

Array iteration and transformation methods Hard
A. b.length === 4, Object.keys(b) is ["0","1","2","3"], and c contains holes.
B. b.length === 4, Object.keys(b) is ["1","3"], and c is [1,2].
C. b.length === 2, Object.keys(b) is ["1","3"], and c has length 4.
D. b.length === 2, Object.keys(b) is ["0","1"], and c is [1,2].

44 What are the final values in [a, b, c, x]?

let x = 1; const { a = x++, b = x++, c = x++ } = { a: undefined, b: null };

Destructuring assignments Hard
A. [1, null, 2, 3]
B. [undefined, null, 1, 2]
C. [1, 2, 3, 4]
D. [1, null, 3, 4]

45 What is returned by apply()?

function apply({ id, ...base }, patch) { return { ...base, ...patch, id }; } const result = apply({ id: 1, role: "user", active: true }, { id: 9, active: false });

Spread and rest operators Hard
A. { role: "user", active: false, id: 9 }
B. { id: 1, role: "user", active: true }
C. { role: "user", active: false, id: 1 }
D. { role: "user", active: true, id: 9 }

46 Consider these modules.

counter.js: export let count = 0; export const increment = () => count++;

main.js: import { count, increment } from "./counter.js"; console.log(count); increment(); console.log(count);

What is printed?

ES modules Hard
A. 0 followed by 1, because imported bindings are live.
B. 1 followed by 1, because dependencies execute after import statements.
C. A TypeError, because an exported variable cannot be changed after import.
D. 0 followed by 0, because imports copy primitive values.

47 Given state = { user: { profile: { name: "Lin" }, permissions: ["read"] }, settings: { theme: "dark" } }, which update changes the name to "Ada" without mutation while preserving the original settings and permissions references?

Immutability principles Hard
A. const next = { ...state, user: { ...state.user, profile: { ...state.user.profile, name: "Ada" } } };
B. const next = { ...state }; next.user.profile.name = "Ada";
C. const next = structuredClone(state); next.user.profile.name = "Ada"; next.settings = { ...next.settings };
D. const next = { ...state, user: state.user }; next.user.profile = { name: "Ada" };

48 A component must return products sorted by ascending score without mutating the items prop and while retaining each product object's identity. Which expression satisfies those requirements?

Functional programming concepts relevant to React Hard
A. items.sort((a, b) => a.score - b.score)
B. [...items].sort((a, b) => a.score - b.score)
C. items.filter(Boolean).reverse()
D. items.map(item => ({ ...item })).sort((a, b) => a.score - b.score)

49 What is true after this code runs?

const original = { nested: { x: 1 }, list: [1, 2] }; const shallow = { ...original }; const deep = structuredClone(original); shallow.nested.x = 7; deep.list.push(3);

Shallow and deep copying mechanisms Hard
A. original.nested.x === 1, original.list.length === 2, and shallow.nested !== original.nested.
B. original.nested.x === 1, original.list.length === 3, and deep.nested.x === 7.
C. original.nested.x === 7, original.list.length === 2, and deep.list.length === 3.
D. original.nested.x === 7, original.list.length === 3, and deep.list === original.list.

50 A React component executes state.user.name = "Ada"; setState(state);, where state is the current object from useState. Which outcome best describes the problem?

Referential equality and state comparison Hard
A. React can bail out because the state reference is unchanged.
B. React always commits because calling a setter bypasses equality checks.
C. React detects the changed nested string through deep comparison.
D. React clones the object automatically before scheduling the update.

51 An application has many URLs, uses the History API for navigation, loads route-specific JavaScript chunks, retrieves data through APIs, and keeps the same document alive between routes. How should it be classified?

Single Page Applications and Multi Page Applications Hard
A. As an MPA, because each route has a distinct browser URL.
B. As an SPA, because client-side navigation reuses one document.
C. As a static site, because the server returns the same shell for every URL and no runtime classification is needed.
D. As an MPA, because route-specific chunks represent separate HTML pages.

52 A component directly changes a rendered element using document.querySelector(...).textContent = "Saved". After an unrelated state update, React restores the previous text. What best explains this behavior?

React philosophy and declarative UI paradigm Hard
A. React periodically reloads the document to remove all manually created browser nodes.
B. React prevents DOM properties from retaining primitive values across event-loop iterations.
C. React treats rendered output as a declaration and reconciles the DOM back to that output.
D. React performs a deep clone of every DOM node whenever any component state changes.

53 Two sibling components must display and update the same selected product, while a third sibling only reads it. Which design best preserves a single source of truth?

Component-based architecture Hard
A. Store the selection in a module variable and force each sibling to render manually.
B. Give each sibling independent state and synchronize them using DOM events.
C. Store the selection in their nearest common ancestor and pass values and callbacks.
D. Duplicate the selected object in every sibling and periodically compare serialized copies.

54 A Vite React project defines VITE_API_URL=https://api.example.com in the applicable environment file. Which client-side expression accesses the value correctly?

Setting up React applications using Vite Hard
A. import.meta.env.API_URL
B. process.env.VITE_API_URL
C. globalThis.VITE_API_URL
D. import.meta.env.VITE_API_URL

55 Which statement accurately distinguishes Vite's development server from its production build process?

Modern React development environment and tooling Hard
A. Development and production both serve every source file as an unchanged browser module.
B. Development serves transformed modules on demand; production bundles and optimizes assets.
C. Production relies on Hot Module Replacement to retrieve dependencies dynamically at runtime.
D. Development eagerly bundles the entire application; production disables static optimization.

56 In a feature-based application, checkout needs a stable selector owned by the cart feature. Which import strategy best protects feature boundaries?

Feature-based project folder structure and best practices Hard
A. Import it directly from features/cart/internal/state/selectors.
B. Duplicate the selector inside checkout so that neither feature imports from the other, even when their rules later diverge.
C. Import it from the public API exposed by features/cart.
D. Move every cart selector into a global utils directory.

57 What visible content is produced by <div>{count && <span>New</span>}</div> when count is the number 0?

JSX syntax and expressions Hard
A. A div containing an empty span.
B. An empty div, because every falsy value is omitted.
C. No div, because the entire JSX expression becomes falsy.
D. A div containing the text 0.

58 What is the semantic effect of calling root.render(<App mode="light" />) and then root.render(<App mode="dark" />) on the same root?

Rendering components into the DOM Hard
A. The second call creates a sibling React tree under the same container automatically.
B. The first application remains mounted while the second application replaces only its DOM event handlers.
C. The second call updates the existing root rather than appending another application.
D. The second call throws because a React root may be rendered exactly once.

59 Which statement about functional component rendering and effects remains valid under concurrent rendering and development StrictMode?

Functional components and render lifecycle Hard
A. A render may be abandoned; effects run after commit, with cleanup before rerun or unmount.
B. Render functions may safely perform network requests because React caches every abandoned invocation.
C. Effect cleanup runs only on final application shutdown, while development mode permanently suppresses duplicate setup calls.
D. Every render is committed exactly once, and effects execute before DOM changes become visible.

60 A list of stateful row components is reordered. Each row currently uses its array index as key. What is the most likely reconciliation issue, and what is the correct remedy?

Introduction to Virtual DOM and reconciliation process Hard
A. The entire DOM is necessarily rebuilt; memoize the array to prevent reconciliation.
B. State follows item values automatically; convert each index key to a random value on every render.
C. State may follow positions; use a stable item identifier as the key.
D. State is always discarded; remove keys so React compares row contents deeply.