Unit 2 - Practice Quiz

INT252 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 What is the primary building block of a React application?

A. Component
B. Package
C. Module
D. DOM

2 Which convention should be followed when naming a React component?

A. PascalCase
B. snake_case
C. kebab-case
D. camelCase

3 Which method is required to be defined in a React Class Component?

A. render
B. getInitialState
C. componentDidMount
D. constructor

4 How do you define a Functional Component in React?

A. function MyComponent() { return <div />; }
B. class MyComponent extends React.Component
C. const MyComponent = new Component()
D. React.createClass({ ... })

5 What is the React Virtual DOM?

A. A database for storing state
B. A direct copy of the browser's DOM
C. A CSS processing engine
D. A lightweight JavaScript representation of the real DOM

6 What is the process of updating the DOM to match the Virtual DOM called?

A. Reconciliation
B. Transpilation
C. Compiling
D. Rendering

7 What does 'Props' stand for in React?

A. Propositions
B. Prototypes
C. Proper HTML
D. Properties

8 Are React Props mutable?

A. No, they are read-only
B. Only inside class components
C. Only inside functional components
D. Yes, always

9 How do you access props in a Class Component?

A. getProps().name
B. this.props.name
C. props.name
D. super.name

10 Which attribute is used to assign a CSS class in React JSX?

A. className
B. class
C. cssClass
D. styleClass

11 What is the data type of the 'style' attribute when using inline styling in React?

A. String
B. Array
C. JavaScript Object
D. CSS File

12 How is the CSS property 'background-color' written in React inline styles?

A. bgColor
B. background-color
C. backgroundColor
D. Background-Color

13 What is the primary advantage of using CSS Modules?

A. It automatically adds TailwindCSS
B. It scopes CSS classes locally to the component
C. It removes the need for CSS
D. It allows writing CSS in PHP

14 Which file extension is typically used for CSS Modules?

A. .module.css
B. .css
C. .js.css
D. .style.js

15 What is TailwindCSS?

A. A component library like MaterialUI
B. A CSS-in-JS library
C. A React state manager
D. A utility-first CSS framework

16 How do you pass a prop named 'color' with value 'red' to a component 'Button'?

A. <Button color='red' />
B. Button.color = 'red'
C. <Button prop:color='red' />
D. <Button>red</Button>

17 In a functional component, how do you access props passed as an argument?

A. props
B. getProps()
C. arguments[0]
D. this.props

18 Can a functional component use State?

A. Yes, using this.state
B. Yes, using the useState hook
C. No, never
D. Only if converted to a Class

19 What keyword is used to inherit from React.Component in a class component?

A. extends
B. uses
C. inherits
D. implements

20 Why is the 'key' prop important in lists?

A. It sorts the list alphabetically
B. It helps React identify which items have changed, added, or removed
C. It styles the list items
D. It is required for CSS Modules

21 Which of the following is NOT a valid way to style a React component?

A. Direct DOM manipulation of style attribute
B. CSS Stylesheets
C. CSS Modules
D. Inline Styling

22 In TailwindCSS, how would you apply a red text color?

A. font-red
B. text-red-500
C. style={{color: 'red'}}
D. color: red

23 What is the correct syntax to import a CSS file 'App.css' into 'App.js'?

A. include 'App.css';
B. import './App.css';
C. using 'App.css';
D. require('App.css');

24 In React, what replaces the HTML 'for' attribute in labels?

A. ref
B. forId
C. labelFor
D. htmlFor

25 What allows React to be faster than traditional DOM manipulation?

A. It uses the Virtual DOM to minimize direct DOM access
B. It runs on the GPU
C. It compresses HTML files
D. It does not use JavaScript

26 How do you use a default value for a prop in a functional component?

A. It is not possible
B. Use global variables
C. Check if it is null inside render
D. Define it in defaultProps or destructure with a default value

27 When using a Class Component, where do you typically initialize state?

A. In the constructor
B. In the return statement
C. In the CSS file
D. In the render method

28 What is 'children' in React props?

A. The child components defined within the opening and closing tags
B. An array of all components in the app
C. The subclass of a component
D. A method to create new components

29 Which configuration file is generated when initializing TailwindCSS?

A. style.config.js
B. css.config.json
C. tailwind.config.js
D. tailwind.json

30 Can a React component return null?

A. Only in development mode
B. Yes, it renders nothing
C. Only in class components
D. No, it throws an error

31 When using CSS Modules, how do you apply a class named 'header'?

A. style={header}
B. class='header'
C. className='header'
D. className={styles.header}

32 What is the main difference between Functional and Class components regarding the this keyword?

A. Functional components do not use this to access props or state
B. Class components do not use this
C. There is no difference
D. Functional components use this extensively

33 Which tool is commonly used to install TailwindCSS in a React project?

A. npm or yarn
B. composer
C. pip
D. maven

34 In the Diffing Algorithm, what happens if the root elements of two trees are different types?

A. React throws an error
B. React keeps the old DOM and appends the new one
C. React updates only the attributes
D. React tears down the old tree and builds the new tree from scratch

35 Can you use multiple CSS classes in the className attribute?

A. Yes, using an array
B. Yes, separated by commas
C. No, only one class is allowed
D. Yes, separated by spaces

36 What syntax allows you to render a component inside another component?

A. import ChildComponent
B. <ChildComponent />
C. new ChildComponent()
D. render(ChildComponent)

37 What is a 'Stateless Functional Component'?

A. A functional component that does not use hooks to manage state
B. A component without props
C. A slow component
D. A component that cannot render HTML

38 If you want to apply dynamic inline styles based on a variable isActive, which is correct?

A. style={{ color: isActive ? 'red' : 'blue' }}
B. css={ isActive ? 'red' : 'blue' }
C. style='color: red'
D. className={isActive}

39 Which feature allows you to pass data from a parent to a child component?

A. Ref
B. Context
C. Props
D. State

40 Which file contains the directives @tailwind base;, @tailwind components;, and @tailwind utilities;?

A. index.html
B. The main CSS entry file (e.g., index.css)
C. App.js
D. package.json

41 How does React handle boolean values in JSX interpolation {true}?

A. It renders nothing
B. It renders 'true'
C. It throws an error
D. It renders a checkbox

42 What is the correct way to export a component as the default export?

A. return ComponentName;
B. module.export = ComponentName;
C. export default ComponentName;
D. export ComponentName;

43 When using inline styles, which unit is assumed for unitless numbers on properties like width?

A. %
B. px (pixels)
C. rem
D. em

44 Can props contain functions?

A. No, only strings and numbers
B. Yes, to handle events or callbacks
C. Only in Class components
D. Only if the function is static

45 What is the purpose of the super(props) call in a Class component constructor?

A. To import CSS
B. To call the parent class constructor and bind this.props
C. To render the component
D. To initialize the state

46 Which of the following is a benefit of Functional Components over Class Components?

A. They support inheritance
B. They have more lifecycle methods
C. They are more verbose
D. They are generally easier to read and test, and require less boilerplate

47 In the context of Virtual DOM, what is 'Batch Update'?

A. Updating the database in batches
B. Grouping multiple state updates into a single re-render for performance
C. Updating all components at once every second
D. Downloading multiple files

48 If a prop is passed to a component but not defined in the component's logic, what happens?

A. The prop is ignored
B. The app crashes
C. React throws a warning
D. It appears in the DOM as an attribute automatically

49 Can you use standard CSS and TailwindCSS in the same project?

A. Yes, they can coexist
B. Only in separate pages
C. Only if you use inline styles
D. No, they conflict

50 Which syntax is used to destructure props in a functional component parameter?

A. function Comp(name, age) { ... }
B. function Comp({ name, age }) { ... }
C. function Comp([name, age]) { ... }
D. function Comp(props) { const name = props.name }