1Which JavaScript API is built-in to browsers and commonly used to make HTTP requests in React applications?
A.Axios
B.Fetch API
C.XMLRequest
D.JQuery
Correct Answer: Fetch API
Explanation:The Fetch API is a native interface in modern browsers that allows you to make network requests similar to XMLHttpRequest.
Incorrect! Try again.
2What type of object does the fetch() function return?
A.XML
B.JSON
C.Promise
D.Array
Correct Answer: Promise
Explanation:The fetch() function returns a Promise that resolves to the Response to that request, whether it is successful or not.
Incorrect! Try again.
3Which library is a popular alternative to the native Fetch API for making HTTP requests in React, offering features like automatic JSON transformation?
A.React-HTTP
B.Axios
C.Router-DOM
D.Redux
Correct Answer: Axios
Explanation:Axios is a promise-based HTTP client for the browser and Node.js that automatically transforms JSON data, unlike the native Fetch API.
Incorrect! Try again.
4In a functional React component, which hook is best suited for performing side effects like data fetching?
A.useState
B.useEffect
C.useReducer
D.useContext
Correct Answer: useEffect
Explanation:useEffect is designed to handle side effects in functional components, such as fetching data, directly interacting with the DOM, and setting up subscriptions.
Incorrect! Try again.
5When using the Fetch API, which method is necessary to parse the response body as JSON?
A..parseJSON()
B..toJSON()
C..json()
D..stringify()
Correct Answer: .json()
Explanation:The .json() method on the Response object returns a promise which resolves with the result of parsing the body text as JSON.
Incorrect! Try again.
6Which HTTP method is used to retrieve data from a server?
A.POST
B.PUT
C.GET
D.DELETE
Correct Answer: GET
Explanation:GET is the HTTP method used specifically to request data from a specified resource.
Incorrect! Try again.
7What is the default HTTP method used by fetch() if none is specified?
A.POST
B.GET
C.PUT
D.UPDATE
Correct Answer: GET
Explanation:If the method option is not defined in the configuration object passed to fetch(), it defaults to a GET request.
Incorrect! Try again.
8When using axios.get(), where is the response data located in the returned object?
A.response.body
B.response.json
C.response.data
D.response.payload
Correct Answer: response.data
Explanation:Axios wraps the response from the server in an object, and the actual data returned by the server is found in the .data property.
Incorrect! Try again.
9Which HTTP method is primarily used to send data to a server to create a new resource?
A.GET
B.DELETE
C.POST
D.HEAD
Correct Answer: POST
Explanation:POST is used to send data to a server to create/update a resource. It is the standard method for creating new records.
Incorrect! Try again.
10When sending a POST request using fetch, what must be included in the headers to tell the server you are sending JSON data?
Explanation:The 'Content-Type' header informs the server about the media type of the resource being sent in the request body.
Incorrect! Try again.
11How do you pass data in the body of a fetch POST request?
A.body: JSON.parse(data)
B.data: JSON.stringify(data)
C.body: JSON.stringify(data)
D.payload: data
Correct Answer: body: JSON.stringify(data)
Explanation: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.
Incorrect! Try again.
12Which HTTP method is typically used to update an existing resource completely?
A.POST
B.PUT
C.GET
D.OPTIONS
Correct Answer: PUT
Explanation:PUT is used to send data to a server to update a resource. It usually replaces the target resource with the request payload.
Incorrect! Try again.
13What is the difference between PUT and PATCH?
A.PUT creates data, PATCH deletes data
B.PUT updates the whole resource, PATCH updates partial data
C.They are identical
D.PATCH is not an HTTP method
Correct Answer: PUT updates the whole resource, PATCH updates partial data
Explanation:PUT expects the new representation to replace the original completely, while PATCH provides a set of instructions to modify the resource partially.
Incorrect! Try again.
14Which HTTP method is used to remove a resource from the server?
A.REMOVE
B.CLEAR
C.DELETE
D.DROP
Correct Answer: DELETE
Explanation:The DELETE method deletes the specified resource.
Incorrect! Try again.
15How does Axios handle HTTP error status codes (like 404 or 500) differently than Fetch?
A.Axios ignores them
B.Axios rejects the promise
C.Fetch rejects the promise
D.Both handle them identically
Correct Answer: Axios rejects the promise
Explanation: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.
Incorrect! Try again.
16What is the standard library used for routing in React applications?
A.react-router-dom
B.react-navigation
C.react-route
D.react-dom-router
Correct Answer: react-router-dom
Explanation:React Router DOM is the standard library for web routing in React, enabling navigation among views of various components.
Incorrect! Try again.
17Which component is used to wrap the entire application to enable routing features?
A.<Router>
B.<BrowserRouter>
C.<RouteProvider>
D.<Navigation>
Correct Answer: <BrowserRouter>
Explanation:BrowserRouter uses the HTML5 history API to keep your UI in sync with the URL and must wrap the app's route definitions.
Incorrect! Try again.
18In React Router v6, which component is used to define a group of routes?
A.<Switch>
B.<Routes>
C.<Router>
D.<Group>
Correct Answer: <Routes>
Explanation:In React Router v6, <Switch> was replaced by <Routes> to look for the best match for the current URL.
Incorrect! Try again.
19Which prop is used in the <Route> component to define the URL path?
A.url
B.href
C.to
D.path
Correct Answer: path
Explanation:The path prop specifies the URL path that triggers the rendering of the component associated with that route.
Incorrect! Try again.
20In React Router v6, which prop is used to specify the component to render for a specific route?
A.component
B.render
C.element
D.view
Correct Answer: element
Explanation:In v6, the element prop is used, and it expects a React element (e.g., <About />) rather than just the component class/function.
Incorrect! Try again.
21How do you define a default route (404 page) that matches when no other route matches?
A.<Route path='404' ... />
B.<Route path='*' ... />
C.<Route default ... />
D.<Route path='?' ... />
Correct Answer: <Route path='*' ... />
Explanation:The path * acts as a catch-all or wildcard that matches any URL not matched by previous routes, commonly used for 404 pages.
Incorrect! Try again.
22Which component is used to create a clickable link that navigates to a new route without reloading the page?
A.<a>
B.<Link>
C.<Nav>
D.<Href>
Correct Answer: <Link>
Explanation:The <Link> component renders an <a> tag but prevents the default browser reload behavior, allowing the router to handle the URL change internally.
Incorrect! Try again.
23Which prop is used in the <Link> component to specify the destination?
A.href
B.src
C.to
D.target
Correct Answer: to
Explanation:The to prop is used in React Router's Link component to describe the target location.
Incorrect! Try again.
24Which hook is used for programmatic navigation in React Router v6?
A.useHistory
B.useNavigation
C.useNavigate
D.useRedirect
Correct Answer: useNavigate
Explanation:React Router v6 introduced useNavigate to replace useHistory. It returns a function that lets you navigate programmatically.
Incorrect! Try again.
25Using useNavigate, how do you navigate to the previous page?
A.navigate.back()
B.navigate(-1)
C.navigate('back')
D.navigate.pop()
Correct Answer: navigate(-1)
Explanation:Passing -1 to the navigate function mimics the browser's back button behavior, moving one step back in the history stack.
Incorrect! Try again.
26How do you define a dynamic parameter in a route path?
A./users/{id}
B./users/:id
C./users/$id
D./users/[id]
Correct Answer: /users/:id
Explanation:The colon : syntax is used to define a dynamic segment (URL parameter) in React Router paths.
Incorrect! Try again.
27Which hook is used to access the values of dynamic URL parameters?
A.useRouter
B.useParams
C.useRouteMatch
D.useLocation
Correct Answer: useParams
Explanation:The useParams hook returns an object of key/value pairs of the dynamic params from the current URL.
Incorrect! Try again.
28What is a Query String?
A.The domain name
B.The part of the URL after the '?' containing key-value pairs
C.The method of the request
D.The JSON body of a request
Correct Answer: The part of the URL after the '?' containing key-value pairs
Explanation:A query string is the portion of a URL where data is passed to a web application and/or back-end database, starting with ?.
Incorrect! Try again.
29Which hook is used to read and modify query parameters in the URL?
A.useQuery
B.useSearchParams
C.useParams
D.useLocation
Correct Answer: useSearchParams
Explanation:The useSearchParams hook is used to read and modify the query string in the URL for the current location.
Incorrect! Try again.
30If the URL is /search?q=react, how do you retrieve the value of 'q' using searchParams?
A.searchParams.q
B.searchParams.get('q')
C.searchParams['q']
D.searchParams.value('q')
Correct Answer: searchParams.get('q')
Explanation:The object returned by useSearchParams adheres to the standard URLSearchParams interface, so the .get() method is used.
Incorrect! Try again.
31How can you pass complex state data (objects) to another route during navigation without showing it in the URL?
A.Using Query Params
B.Using the state property in navigate or Link
C.Using localStorage
D.Using cookies
Correct Answer: Using the state property in navigate or Link
Explanation:Both <Link to='...' state={data}> and navigate('...', { state: data }) allow passing arbitrary data to the destination route via the history stack location state.
Incorrect! Try again.
32Which hook allows you to access the state passed via navigation?
A.useParams
B.useNavigate
C.useLocation
D.useHistory
Correct Answer: useLocation
Explanation:The useLocation hook returns the location object, which contains the state property passed during navigation.
Incorrect! Try again.
33What is the difference between <Link> and <NavLink>?
A.NavLink is for external links
B.NavLink provides styling attributes for the 'active' state
C.Link causes a page reload
D.There is no difference
Correct Answer: NavLink provides styling attributes for the 'active' state
Explanation: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.
Incorrect! Try again.
34When using useEffect to fetch data, what should be the second argument to ensure the data is fetched only once on component mount?
A.null
B.undefined
C.[ ] (empty array)
D.No argument
Correct Answer: [ ] (empty array)
Explanation: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.
Incorrect! Try again.
35Why is it important to handle 'loading' states when fetching data?
A.To prevent the app from crashing
B.To improve user experience by indicating activity
C.Because fetch requires it
D.To save bandwidth
Correct Answer: To improve user experience by indicating activity
Explanation:Data fetching is asynchronous. Displaying a loader informs the user that the application is working and not frozen while waiting for the response.
Incorrect! Try again.
36In an Axios request, what does axios.post('/api/user', { name: 'John' }) do?
A.Sends a GET request with query params
B.Sends a POST request with a JSON body containing the name
C.Updates the route to /api/user
D.Deletes the user John
Correct Answer: Sends a POST request with a JSON body containing the name
Explanation:The second argument in axios.post is the data payload, which Axios automatically serializes to JSON.
Incorrect! Try again.
37What is the purpose of <Outlet> in React Router?
A.To link to external sites
B.To render child routes within a parent route layout
C.To handle 404 errors
D.To output console logs
Correct Answer: To render child routes within a parent route layout
Explanation: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.
Incorrect! Try again.
38How do you install Axios in a React project?
A.npm add fetch
B.npm install axios
C.import axios from react
D.It is built-in
Correct Answer: npm install axios
Explanation:Axios is a third-party library and must be installed via a package manager like npm or yarn.
Incorrect! Try again.
39What property in the Link component replaces the current entry in the history stack instead of adding a new one?
A.push
B.replace
C.swap
D.history
Correct Answer: replace
Explanation:The replace boolean prop, when true, replaces the current entry in the history stack so the user cannot go back to the previous page.
Incorrect! Try again.
40If you need to execute code after a Fetch request is successfully completed, which Promise method do you use?
A..catch()
B..then()
C..finally()
D..next()
Correct Answer: .then()
Explanation:The .then() method is used to handle the fulfilled state of a Promise, executing code with the resulting value.
Incorrect! Try again.
41Which Axios feature allows you to intercept requests or responses before they are handled by .then() or .catch()?
A.Middleware
B.Interceptors
C.Controllers
D.Transformers
Correct Answer: Interceptors
Explanation: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.
Incorrect! Try again.
42When using async/await with fetch, what keyword must be used before the function definition?
A.await
B.async
C.promise
D.defer
Correct Answer: async
Explanation:The async keyword defines an asynchronous function, which enables the use of the await keyword inside it.
Incorrect! Try again.
43What is a common use case for passing data via Query Parameters?
A.Sending passwords
B.Filtering or sorting a list on a page
C.Uploading files
D.Creating new database records
Correct Answer: Filtering or sorting a list on a page
Explanation:Query parameters are visible in the URL and are ideal for bookmarkable states like search queries, page numbers, or sort orders.
Incorrect! Try again.
44How do you access the history object directly in React Router v6?
A.useHistory()
B.You cannot access it directly, use useNavigate()
C.window.history
D.withRouter()
Correct Answer: You cannot access it directly, use useNavigate()
Explanation:React Router v6 abstracts the history object. While you can use window.history, the router-specific navigation is handled via useNavigate.
Incorrect! Try again.
45In a nested route structure users/profile, if the path users is the parent, where does profile render?
A.On a new page completely
B.Inside the parent's <Outlet />
C.Above the parent component
D.It replaces the parent component
Correct Answer: Inside the parent's <Outlet />
Explanation:Nested routes render inside the placeholder <Outlet /> component placed within the parent route's element.
Incorrect! Try again.
46Which method is used in fetch to catch network errors?
A..error()
B..catch()
C..fail()
D..reject()
Correct Answer: .catch()
Explanation:The .catch() method handles rejected promises, which in fetch typically occurs during network failures (like DNS issues or loss of connectivity).
Incorrect! Try again.
47If you want to send an Authorization token in the header of an Axios request, where do you put it?
A.In the URL
B.In the data body
C.In the headers object within the config argument
D.In the method name
Correct Answer: In the headers object within the config argument
Explanation:Headers are passed in the configuration object (usually the 3rd argument for POST/PUT, 2nd for GET) under the headers key.
Incorrect! Try again.
48What is the correct syntax to import React Router components?
A.import { BrowserRouter } from 'react-router';
B.import { BrowserRouter } from 'react-router-dom';
C.import { Router } from 'react';
D.import { Route } from 'react-dom';
Correct Answer: import { BrowserRouter } from 'react-router-dom';
Explanation:The components for web-based routing are located in the react-router-dom package.
Incorrect! Try again.
49When using fetch, if response.ok is false, what does it usually imply?
A.Network failure
B.Server returned a status code like 4xx or 5xx
C.JSON parsing failed
D.The request was successful
Correct Answer: Server returned a status code like 4xx or 5xx
Explanation: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.
Incorrect! Try again.
50Which of the following is an advantage of using async/await over .then() chaining?
A.It is faster
B.It makes the code look synchronous and more readable
C.It doesn't use Promises
D.It works in older browsers without polyfills
Correct Answer: It makes the code look synchronous and more readable
Explanation:Async/await is syntactic sugar over Promises that avoids 'callback hell' or long promise chains, making the code easier to read and debug.
Incorrect! Try again.
Give Feedback
Help us improve by sharing your thoughts or reporting issues.