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. (a, b) -> a + b
C. function => (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. const
C. static
D. var

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

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

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. include
B. publish
C. export
D. require

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. Creating a new value instead of modifying the old one
D. Storing every value in a global variable

8 What is a pure function?

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

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

Shallow and deep copying mechanisms Easy
A. It removes all nested object properties
B. It recursively copies every nested object
C. It keeps references to the same nested objects
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 point to the same object
B. When they contain properties with equal values
C. When they use the same property names
D. When they were created on the same line

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

Single Page Applications and Multi Page Applications Easy
A. It reloads a new HTML document for every action
B. It stores each component in a separate website
C. It updates views without fully reloading the page
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. Building every screen with separate HTML documents
C. Describing what the UI should look like for the current state
D. Writing browser commands in a fixed execution order

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 create vite@latest
D. npm install react-page

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

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

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

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

17 How is a JavaScript expression inserted into JSX?

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

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

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

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

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

20 What does React do during reconciliation?

Introduction to Virtual DOM and reconciliation process Easy
A. It compares UI representations to determine needed updates
B. It converts every component into a database table
C. It deletes the entire DOM after each state change
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 creates a new this for team.
D. The arrow callback searches the global object and creates a permanent this binding for every method.

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. 3, 3, and 3
B. A ReferenceError occurs
C. 0, 0, and 0
D. 0, 1, and 2

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. ['pen', 'book']
B. [true, true]
C. ['PEN', 'BAG', '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. undefined-viewer-Pune
B. Mira-undefined-Pune
C. Mira-viewer-undefined
D. Mira-viewer-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 dark
B. dark dark
C. light light
D. dark light

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 => ({ ...prev, profile: { ...prev.profile, city: 'Goa' } }));
B. setUser(prev => ({ ...prev, profile: { city: 'Goa' } }));
C. setUser(prev => { const next = { ...prev }; next.profile.city = 'Goa'; return next; });
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 visit = user => ++user.views;
B. const fullName = user => user.first + ' ' + user.last;
C. const arrange = items => items.sort();
D. const timestamp = () => Date.now();

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 = JSON.parse(JSON.stringify(original));
C. const copy = { ...original };
D. const copy = structuredClone(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. push creates a new array, so the update is immutable.
B. React deeply compares every array element before deciding whether to render the complete component tree.
C. Object.is(current, next) is true, so React may skip the update.
D. Object.is(current, next) is false, so React must rerender.

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. An SPA using client-side routing
B. An MPA using server-side page routing
C. A static site that reloads every document and reconstructs the complete interface on each navigation
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. return <p>{isOnline && 'Online'}</p>;
B. document.querySelector('p').textContent = isOnline ? 'Online' : 'Offline';
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. Store all card markup in App and select it using DOM element IDs.
B. Copy the complete card markup into every page that displays a product.
C. Create one large page component that contains every possible card variant and directly modifies each element.
D. Create a reusable ProductCard that receives product data and an add handler.

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

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

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 build
C. npm run preview
D. npm run lint

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 checkout code in shared and duplicate Button inside every feature.
B. Place every component and hook together in one root-level components directory.
C. Place all JavaScript files directly inside src and distinguish their purpose only through long filenames.
D. Place checkout code in features/checkout and Button in shared/components.

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>{if (count) count + ' items'}</span>
B. <span>{count && count + ' items'}</span>
C. <span>{count || 'No items'}</span>
D. <span>{count ? count + ' items' : 'No 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. createRoot(document.getElementById('root')).render(<App />);
B. createRoot(document.querySelector('App')).mount(<div id='root' />);
C. document.getElementById('root').render(createRoot(<App />));
D. createRoot(<App />).render(document.getElementById('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. loadUser(userId); return <Profile />;
C. useEffect(() => { loadUser(userId); }, [userId]);
D. useEffect(() => { loadUser(userId); }, []);

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={item.name + Date.now()} item={item} />
B. <Row key={Math.random()} item={item} />
C. <Row key={item.id} item={item} />
D. <Row key={index} 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. undefined
B. 20
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 undefined because typeof safely handles every inaccessible binding.
B. It throws a ReferenceError before logging anything.
C. It logs number and then changes the outer value to 2.
D. It logs number because the outer variable is visible.

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 === 2, Object.keys(b) is ["0","1"], and c is [1,2].
C. b.length === 4, Object.keys(b) is ["1","3"], and c is [1,2].
D. b.length === 2, Object.keys(b) is ["1","3"], and c has length 4.

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. [undefined, null, 1, 2]
B. [1, 2, 3, 4]
C. [1, null, 3, 4]
D. [1, null, 2, 3]

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: 1 }
B. { role: "user", active: false, id: 9 }
C. { id: 1, role: "user", active: true }
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. A TypeError, because an exported variable cannot be changed after import.
C. 0 followed by 0, because imports copy primitive values.
D. 1 followed by 1, because dependencies execute after import statements.

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 }; next.user.profile.name = "Ada";
B. const next = { ...state, user: { ...state.user, profile: { ...state.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.filter(Boolean).reverse()
C. [...items].sort((a, b) => a.score - b.score)
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 === 7, original.list.length === 2, and deep.list.length === 3.
C. original.nested.x === 7, original.list.length === 3, and deep.list === original.list.
D. original.nested.x === 1, original.list.length === 3, and deep.nested.x === 7.

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 always commits because calling a setter bypasses equality checks.
B. React clones the object automatically before scheduling the update.
C. React detects the changed nested string through deep comparison.
D. React can bail out because the state reference is unchanged.

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 SPA, because client-side navigation reuses one document.
B. As an MPA, because each route has a distinct browser URL.
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 treats rendered output as a declaration and reconciles the DOM back to that output.
B. React performs a deep clone of every DOM node whenever any component state changes.
C. React periodically reloads the document to remove all manually created browser nodes.
D. React prevents DOM properties from retaining primitive values across event-loop iterations.

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. Give each sibling independent state and synchronize them using DOM events.
B. Store the selection in their nearest common ancestor and pass values and callbacks.
C. Store the selection in a module variable and force each sibling to render manually.
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. process.env.VITE_API_URL
B. import.meta.env.VITE_API_URL
C. import.meta.env.API_URL
D. globalThis.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 serves transformed modules on demand; production bundles and optimizes assets.
B. Development and production both serve every source file as an unchanged browser module.
C. Development eagerly bundles the entire application; production disables static optimization.
D. Production relies on Hot Module Replacement to retrieve dependencies dynamically at runtime.

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. Duplicate the selector inside checkout so that neither feature imports from the other, even when their rules later diverge.
B. Import it directly from features/cart/internal/state/selectors.
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. An empty div, because every falsy value is omitted.
B. No div, because the entire JSX expression becomes falsy.
C. A div containing the text 0.
D. A div containing an empty span.

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 updates the existing root rather than appending another application.
B. The second call throws because a React root may be rendered exactly once.
C. The first application remains mounted while the second application replaces only its DOM event handlers.
D. The second call creates a sibling React tree under the same container automatically.

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

Functional components and render lifecycle Hard
A. Render functions may safely perform network requests because React caches every abandoned invocation.
B. Effect cleanup runs only on final application shutdown, while development mode permanently suppresses duplicate setup calls.
C. A render may be abandoned; effects run after commit, with cleanup before rerun or unmount.
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 is always discarded; remove keys so React compares row contents deeply.
C. State follows item values automatically; convert each index key to a random value on every render.
D. State may follow positions; use a stable item identifier as the key.