Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Which JavaScript API is built-in to browsers and commonly used to make HTTP requests in React applications?
Not quite. Try another option.
Answer: Fetch API
The Fetch API is a native interface in modern browsers that allows you to make network requests similar to XMLHttpRequest.
Question 2 of 50
What type of object does the fetch() function return?
Not quite. Try another option.
Answer: Promise
The fetch() function returns a Promise that resolves to the Response to that request, whether it is successful or not.
Question 3 of 50
Which library is a popular alternative to the native Fetch API for making HTTP requests in React, offering features like automatic JSON transformation?
Not quite. Try another option.
Answer: Axios
Axios is a promise-based HTTP client for the browser and Node.js that automatically transforms JSON data, unlike the native Fetch API.
Question 4 of 50
In a functional React component, which hook is best suited for performing side effects like data fetching?
Not quite. Try another option.
Answer: useEffect
useEffect is designed to handle side effects in functional components, such as fetching data, directly interacting with the DOM, and setting up subscriptions.
Question 5 of 50
When using the Fetch API, which method is necessary to parse the response body as JSON?
Not quite. Try another option.
Answer: .json()
The .json() method on the Response object returns a promise which resolves with the result of parsing the body text as JSON.
Question 6 of 50
Which HTTP method is used to retrieve data from a server?
Not quite. Try another option.
Answer: GET
GET is the HTTP method used specifically to request data from a specified resource.
Question 7 of 50
What is the default HTTP method used by fetch() if none is specified?
Not quite. Try another option.
Answer: GET
If the method option is not defined in the configuration object passed to fetch(), it defaults to a GET request.
Question 8 of 50
When using axios.get(), where is the response data located in the returned object?
Not quite. Try another option.
Answer: response.data
Axios wraps the response from the server in an object, and the actual data returned by the server is found in the .data property.
Question 9 of 50
Which HTTP method is primarily used to send data to a server to create a new resource?
Not quite. Try another option.
Answer: POST
POST is used to send data to a server to create/update a resource. It is the standard method for creating new records.
Question 10 of 50
When sending a POST request using fetch, what must be included in the headers to tell the server you are sending JSON data?
Not quite. Try another option.
Answer: 'Content-Type': 'application/json'
The 'Content-Type' header informs the server about the media type of the resource being sent in the request body.
Question 11 of 50
How do you pass data in the body of a fetch POST request?
Not quite. Try another option.
Answer: body: JSON.stringify(data)
The fetch API requires the body to be a string (or Blob/BufferSource), so a JavaScript object must be converted to a JSON string using JSON.stringify.
Question 12 of 50
Which HTTP method is typically used to update an existing resource completely?
Not quite. Try another option.
Answer: PUT
PUT is used to send data to a server to update a resource. It usually replaces the target resource with the request payload.
Question 13 of 50
What is the difference between PUT and PATCH?
Not quite. Try another option.
Answer: PUT updates the whole resource, PATCH updates partial data
PUT expects the new representation to replace the original completely, while PATCH provides a set of instructions to modify the resource partially.
Question 14 of 50
Which HTTP method is used to remove a resource from the server?
Not quite. Try another option.
Answer: DELETE
The DELETE method deletes the specified resource.
Question 15 of 50
How does Axios handle HTTP error status codes (like 404 or 500) differently than Fetch?
Not quite. Try another option.
Answer: Axios rejects the promise
Axios automatically rejects the promise for HTTP status codes outside the 2xx range. Fetch resolves the promise even on 404 or 500 (unless there is a network failure), requiring manual checking of response.ok.
Question 16 of 50
What is the standard library used for routing in React applications?
Not quite. Try another option.
Answer: react-router-dom
React Router DOM is the standard library for web routing in React, enabling navigation among views of various components.
Question 17 of 50
Which component is used to wrap the entire application to enable routing features?
Not quite. Try another option.
Answer: <BrowserRouter>
BrowserRouter uses the HTML5 history API to keep your UI in sync with the URL and must wrap the app's route definitions.
Question 18 of 50
In React Router v6, which component is used to define a group of routes?
Not quite. Try another option.
Answer: <Routes>
In React Router v6, <Switch> was replaced by <Routes> to look for the best match for the current URL.
Question 19 of 50
Which prop is used in the <Route> component to define the URL path?
Not quite. Try another option.
Answer: path
The path prop specifies the URL path that triggers the rendering of the component associated with that route.
Question 20 of 50
In React Router v6, which prop is used to specify the component to render for a specific route?
Not quite. Try another option.
Answer: element
In v6, the element prop is used, and it expects a React element (e.g., <About />) rather than just the component class/function.
Question 21 of 50
How do you define a default route (404 page) that matches when no other route matches?
Not quite. Try another option.
Answer: <Route path='*' ... />
The path * acts as a catch-all or wildcard that matches any URL not matched by previous routes, commonly used for 404 pages.
Question 22 of 50
Which component is used to create a clickable link that navigates to a new route without reloading the page?
Not quite. Try another option.
Answer: <Link>
The <Link> component renders an <a> tag but prevents the default browser reload behavior, allowing the router to handle the URL change internally.
Question 23 of 50
Which prop is used in the <Link> component to specify the destination?
Not quite. Try another option.
Answer: to
The to prop is used in React Router's Link component to describe the target location.
Question 24 of 50
Which hook is used for programmatic navigation in React Router v6?
Not quite. Try another option.
Answer: useNavigate
React Router v6 introduced useNavigate to replace useHistory. It returns a function that lets you navigate programmatically.
Question 25 of 50
Using useNavigate, how do you navigate to the previous page?
Not quite. Try another option.
Answer: navigate(-1)
Passing -1 to the navigate function mimics the browser's back button behavior, moving one step back in the history stack.
Question 26 of 50
How do you define a dynamic parameter in a route path?
Not quite. Try another option.
Answer: /users/:id
The colon : syntax is used to define a dynamic segment (URL parameter) in React Router paths.
Question 27 of 50
Which hook is used to access the values of dynamic URL parameters?
Not quite. Try another option.
Answer: useParams
The useParams hook returns an object of key/value pairs of the dynamic params from the current URL.
Question 28 of 50
What is a Query String?
Not quite. Try another option.
Answer: The part of the URL after the '?' containing key-value pairs
A query string is the portion of a URL where data is passed to a web application and/or back-end database, starting with ?.
Question 29 of 50
Which hook is used to read and modify query parameters in the URL?
Not quite. Try another option.
Answer: useSearchParams
The useSearchParams hook is used to read and modify the query string in the URL for the current location.
Question 30 of 50
If the URL is /search?q=react, how do you retrieve the value of 'q' using searchParams?
Not quite. Try another option.
Answer: searchParams.get('q')
The object returned by useSearchParams adheres to the standard URLSearchParams interface, so the .get() method is used.
Question 31 of 50
How can you pass complex state data (objects) to another route during navigation without showing it in the URL?
Not quite. Try another option.
Answer: Using the state property in navigate or Link
Both <Link to='...' state={data}> and navigate('...', { state: data }) allow passing arbitrary data to the destination route via the history stack location state.
Question 32 of 50
Which hook allows you to access the state passed via navigation?
Not quite. Try another option.
Answer: useLocation
The useLocation hook returns the location object, which contains the state property passed during navigation.
Question 33 of 50
What is the difference between <Link> and <NavLink>?
Not quite. Try another option.
Answer: NavLink provides styling attributes for the 'active' state
NavLink is a special version of Link that will add styling attributes (like a class) to the rendered element when it matches the current URL.
Question 34 of 50
When using useEffect to fetch data, what should be the second argument to ensure the data is fetched only once on component mount?
Not quite. Try another option.
Answer: [ ] (empty array)
An empty dependency array tells React that the effect doesn't depend on any values from props or state, so it never needs to re-run after the initial render.
Question 35 of 50
Why is it important to handle 'loading' states when fetching data?
Not quite. Try another option.
Answer: To improve user experience by indicating activity
Data fetching is asynchronous. Displaying a loader informs the user that the application is working and not frozen while waiting for the response.
Question 36 of 50
In an Axios request, what does axios.post('/api/user', { name: 'John' }) do?
Not quite. Try another option.
Answer: Sends a POST request with a JSON body containing the name
The second argument in axios.post is the data payload, which Axios automatically serializes to JSON.
Question 37 of 50
What is the purpose of <Outlet> in React Router?
Not quite. Try another option.
Answer: To render child routes within a parent route layout
An <Outlet> should be used in parent route elements to render their child route elements. This allows nested UI to show up when child routes are rendered.
Question 38 of 50
How do you install Axios in a React project?
Not quite. Try another option.
Answer: npm install axios
Axios is a third-party library and must be installed via a package manager like npm or yarn.
Question 39 of 50
What property in the Link component replaces the current entry in the history stack instead of adding a new one?
Not quite. Try another option.
Answer: replace
The replace boolean prop, when true, replaces the current entry in the history stack so the user cannot go back to the previous page.
Question 40 of 50
If you need to execute code after a Fetch request is successfully completed, which Promise method do you use?
Not quite. Try another option.
Answer: .then()
The .then() method is used to handle the fulfilled state of a Promise, executing code with the resulting value.
Question 41 of 50
Which Axios feature allows you to intercept requests or responses before they are handled by .then() or .catch()?
Not quite. Try another option.
Answer: Interceptors
Axios Interceptors allow you to run code or modify the request/response object globally before the request is sent or after the response is received.
Question 42 of 50
When using async/await with fetch, what keyword must be used before the function definition?
Not quite. Try another option.
Answer: async
The async keyword defines an asynchronous function, which enables the use of the await keyword inside it.
Question 43 of 50
What is a common use case for passing data via Query Parameters?
Not quite. Try another option.
Answer: Filtering or sorting a list on a page
Query parameters are visible in the URL and are ideal for bookmarkable states like search queries, page numbers, or sort orders.
Question 44 of 50
How do you access the history object directly in React Router v6?
Not quite. Try another option.
Answer: You cannot access it directly, use useNavigate()
React Router v6 abstracts the history object. While you can use window.history, the router-specific navigation is handled via useNavigate.
Question 45 of 50
In a nested route structure users/profile, if the path users is the parent, where does profile render?
Not quite. Try another option.
Answer: Inside the parent's <Outlet />
Nested routes render inside the placeholder <Outlet /> component placed within the parent route's element.
Question 46 of 50
Which method is used in fetch to catch network errors?
Not quite. Try another option.
Answer: .catch()
The .catch() method handles rejected promises, which in fetch typically occurs during network failures (like DNS issues or loss of connectivity).
Question 47 of 50
If you want to send an Authorization token in the header of an Axios request, where do you put it?
Not quite. Try another option.
Answer: In the headers object within the config argument
Headers are passed in the configuration object (usually the 3rd argument for POST/PUT, 2nd for GET) under the headers key.
Question 48 of 50
What is the correct syntax to import React Router components?
Not quite. Try another option.
Answer: import { BrowserRouter } from 'react-router-dom';
The components for web-based routing are located in the react-router-dom package.
Question 49 of 50
When using fetch, if response.ok is false, what does it usually imply?
Not quite. Try another option.
Answer: Server returned a status code like 4xx or 5xx
response.ok is a boolean that is true if the status code is in the range 200-299. If false, it indicates a client or server error.
Question 50 of 50
Which of the following is an advantage of using async/await over .then() chaining?
Not quite. Try another option.
Answer: It makes the code look synchronous and more readable
Async/await is syntactic sugar over Promises that avoids 'callback hell' or long promise chains, making the code easier to read and debug.
That's unit 5
Answer a few questions and your score shows up here.
Nearly through. Did unit 5 of INT252 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 5 of INT252 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.