Question 1

CoITB EXAM 2. What is the main purpose of React Testing Library?

  • To style React components
  • To automate routing
  • To test React components from the user’s perspective
  • To debug JavaScript syntax

Question 2

How do you prevent the default behavior in an event handler?

  • event.preventReact()
  • stopDefault()
  • event.preventDefault()
  • event.preventDefault

Question 3

What does the history object in React Router facilitate?

  • Accessing browser history
  • Managing component state
  • Handling form submissions
  • Programmatic navigation

Question 4

What are React components?

  • Functions that return React elements
  • HTML elements
  • Javascript objects
  • CSS styles

Question 5

What is a synthetic event in React?

  • An event from a browser plugin
  • A custom animation handler
  • A cross-browser wrapper around the native event
  • A manual dispatch tool

Question 6

What does the onClick event handler do in React?

  • Updates the DOM directly
  • Attaches a CSS class
  • Executes a function when a user clicks an element
  • Submits a form by default

Question 7

How do you access props inside a functional component?

  • Using this.props
  • Using props
  • Using this.state
  • Using state

Question 8

What is the key difference between functional and class components in React?

  • Functional components use the this keyword
  • Class components use hooks
  • Functional components don’t have lifecycle methods
  • Class components don’t support props

Question 9

Which is the correct syntax to initialize state using useState()?

  • const state = useState(0);
  • const [count, setCount] = useState(0);
  • setState(count = 0);
  • state(count).useState(0);

Question 10

Which of the following is an example of a unit test?

  • Testing how multiple components interact with each other
  • Testing the full application flow
  • Testing if a button component renders with the correct text
  • Testing server responses

Question 11

Which object is automatically passed to event handler functions in React?

  • nativeEvent
  • documentEvent
  • windowEvent
  • SyntheticEvent

Question 12

How do you pass data from a parent component to a child component?

  • Using state
  • Using hooks
  • Using props
  • Using event

Question 13

How do you create a functional component in React?

  • Using the class keyword
  • Using the extends keyword
  • Using the function keyword
  • Using the render keyword

Question 14

What does onMouseEnter do in React?

  • Triggers when the mouse is clicked
  • Triggers when the mouse leaves the element
  • Triggers when the mouse hovers over the element
  • Triggers when the element is dragged

Question 15

What is the primary purpose of the useEffect hook?

  • To manage component state
  • To run code after the component renders
  • To create global context
  • To handle form validation

Question 64 / 87

Which file extension is commonly used for React components?

  • .jsx
  • .cssx
  • .javx

Question 65 / 87

Which of the following is a key best practice when working with React lists?

  • Using random values as keys
  • Ensuring keys remain inconsistent across renders
  • Using array indices as keys for dynamic lists
  • Making keys unique among siblings

Question 66 / 87

What is the purpose of the useRef hook in React?

  • To subscribe to changes in the component’s props
  • To access the DOM node of a component
  • To manage component state
  • To perform asynchronous operations

Question 67 / 87

What is the correct way to define a route in React Router v6?

  • <Route path="/about" to={About} />
  • <Route name="/about" element={<About />} />
  • <Route path="/about" element={<About />} />
  • <Router path="/about" render={<About />} />

Question 68 / 87

What is the purpose of props in React?

  • To manage component state
  • To handle user events
  • To pass data from parent to child components
  • To style components

Question 69 / 87

Which feature is unique to styled-components?

  • Inline styles
  • Scoped component-level styles
  • Precompiled CSS files
  • Global styles only

Question 70 / 87

What is the purpose of the useMemo hook in React?

  • To memoize callback functions
  • To manage component state
  • To perform data fetching
  • To optimize expensive calculations

Question 71 / 87

What is the correct way to define a functional component in React?

  • function MyComponent[]
  • function MyComponent() { return <div>Hello</div>; }
  • component MyComponent() {}
  • React.defineComponent('MyComponent')

Question 72 / 87

How do you specify default values for props in a React component?

  • By using the defaultProps property
  • By using the defaultValues property
  • By passing values directly to props
  • By using the PropTypes library

Question 73 / 87

Which mechanism allows passing data between routes without exposing it in the URL?

  • URL parameters
  • Query parameters
  • State management libraries
  • Local storage

Question 74 / 87

How do you return HTML in a React component?

  • Using quotes “HTML here”
  • With a return statement containing JSX
  • By writing directly inside renderHTML()
  • Through a CSS file

Question 75 / 87

What is the purpose of useEffect(() => { … }, [])?

  • It runs after every render
  • It only runs on mount
  • It runs when the component is unmounted
  • It prevents rendering

Question 76 / 87

What is the purpose of the export default statement in a React component file?

  • To add a CSS file
  • To define a stateful component
  • To allow the component to be imported elsewhere
  • To reset the component

Question 77 / 87

What is the purpose of the useContext hook in React? CoITB EXAM 2.

  • To create a new component
  • To pass data from child to parent
  • To manage global state only
  • To avoid prop drilling

State Management

Question 54

What is the difference between controlled and uncontrolled components in React? CoITB EXAM 2.

  • Controlled components have their state managed by React, while uncontrolled components manage their state internally
  • Controlled components cannot have event handlers, while uncontrolled components can
  • Controlled components are faster than uncontrolled components
  • Controlled components require fewer resources than uncontrolled components

Question 56

How do you update state in React?

  • By directly modifying the state object
  • By calling the setState() method
  • By using props
  • By using the render() method

Lifecycle Methods and Hooks

Question 55

What is the purpose of the shouldComponentUpdate() method in React?

  • To update the component’s state
  • To handle events
  • To control whether a component should re-render
  • To perform side effects

Event Handling

Question 57

What technique is used for ensuring the validity of user input in forms?

  • Controlled components
  • Dynamic rendering
  • Form submission handling
  • Form validation

Components

Question 58

What does JSX stand for?

  • Java Syntax eXtension
  • JavaScript and XML
  • JavaStyleXHTML
  • JavaScript Extension Layer

Styling

Question 59

What is the main idea behind Tailwind CSS?

  • Writing inline JavaScript styles
  • Applying component-scoped styles
  • Using utility classes to build designs without writing custom CSS
  • Loading styles dynamically from a CDN

Question 61

Which of the following is a valid Tailwind class for adding padding?

  • padding-10
  • pad-4
  • p-4 CoITB EXAM 2.
  • padding-left: 4px

Question 63

Which file extension is used for SASS files? CoITB EXAM 2.

  • .sass or .scss
  • .style
  • .csss
  • .jsx

Question 64

Styled-components is an example of which styling pattern?

  • CSS Modules
  • CSS-in-JS
  • SASS
  • Tailwind CSS

Rendering Performance

Question 62

How do you optimize performance in React?

  • By using memoization techniques
  • By minimizing re-renders with PureComponent or React.memo
  • By implementing virtualization for large lists
  • All of the above

Question 80

What feature of React allows developers to reuse code components?

  • Props
  • State
  • Lifecycle methods
  • Virtual DOM

Facebook
WhatsApp
Twitter
LinkedIn
Pinterest

Leave a Comment