Front End Development Front End Development Frameworks & State Management 1 — Questions and Answers
Question 1: In React, what is the purpose of the useState hook?
- To fetch data from an API
- To add local state to a functional component (Correct answer)
- To manage global application state
- To handle side effects
Correct answer: To add local state to a functional component
The useState hook allows functional components to declare and update local state variables, triggering re-renders when state changes.
Question 2: What is the virtual DOM in React?
- A browser extension for debugging
- A lightweight in-memory representation of the real DOM used to optimize updates (Correct answer)
- A CSS-in-JS library
- A server-side rendering technique
Correct answer: A lightweight in-memory representation of the real DOM used to optimize updates
React's virtual DOM is an in-memory object tree that React uses to diff against the real DOM and apply only the minimal necessary changes.
Question 3: In Vue.js, which directive conditionally renders an element by toggling its display property?
- v-if
- v-show (Correct answer)
- v-bind
- v-for
Correct answer: v-show
v-show toggles an element's CSS display property without removing it from the DOM, unlike v-if which adds/removes the element entirely.
Question 4: What is the purpose of Redux in a React application?
- To style components with CSS
- To manage and centralize application state (Correct answer)
- To handle routing between pages
- To compile JSX to JavaScript
Correct answer: To manage and centralize application state
Redux provides a centralized store for application state, making state predictable and easier to debug across large React applications.
Question 5: In Angular, what is a service used for?
- Defining the HTML template
- Sharing data and business logic across multiple components (Correct answer)
- Styling component UI
- Configuring routing
Correct answer: Sharing data and business logic across multiple components
Angular services are singleton classes used to share data, logic, and functionality across components via dependency injection.
Question 6: What is JSX in React?
- A state management library
- A JavaScript XML syntax extension that allows HTML-like code in JavaScript (Correct answer)
- A CSS preprocessor
- A testing framework
Correct answer: A JavaScript XML syntax extension that allows HTML-like code in JavaScript
JSX is a syntax extension for JavaScript that lets developers write HTML-like markup directly within JavaScript files, compiled by Babel.
In React, what is the purpose of the useState hook?