Deck 3 Flashcards
What is the lifecycle in React?
The React lifecycle refers to the series of methods that are invoked at different stages of a component’s existence: mounting, updating, and unmounting. These methods include componentDidMount, componentDidUpdate, and componentWillUnmount.
What is a Higher-Order Component?
A Higher-Order Component (HOC) is a function that takes a component and returns a new component with additional props or behavior. It’s used to reuse component logic, such as handling authentication or data fetching.
What is the difference between useMemo and React.memo?
useMemo is a React hook that memoizes the result of a computation, while React.memo is a higher-order component that memoizes the entire component. useMemo optimizes specific calculations within a component, while React.memo prevents unnecessary re-renders of the entire component.
What is a memory leak?
: A memory leak occurs when a program allocates memory but fails to release it after it’s no longer needed, leading to reduced performance over time. In React, this can happen if event listeners or intervals are not properly cleaned up.
What is the dynamic index in TypeScript?
A dynamic index in TypeScript allows you to define an index signature in an object type, specifying that an object can have properties with keys of a certain type and values of a certain type, such as [key: string]: number.
What is the grid system in CSS?
The grid system in CSS is a layout structure that divides a web page into rows and columns, allowing for precise control over the placement and alignment of elements. CSS Grid Layout and Flexbox are common techniques used.
What is lifting state up in React?
Lifting state up in React refers to moving state from child components to a common parent component to manage shared state. This is done to allow sibling components to access and update the shared state.
What is a custom hook in React.js?
A custom hook is a JavaScript function that uses one or more built-in React hooks (like useState or useEffect) to encapsulate and reuse logic across multiple components. It helps keep components clean and reusable
What is the difference between null and undefined? ❓
null is an assigned value representing the intentional absence of any object value, while undefined means a variable has been declared but not yet assigned a value. Both are falsy values but used in different contexts.
What is the output of [] == []?
: The output of [] == [] is false because in JavaScript, objects and arrays are compared by reference, not by value. Two different empty arrays are different objects in memory, so the comparison returns false.
What are Primitive Types and Union Types?
Primitive types in TypeScript are the basic data types such as string, number, boolean, etc. Union types allow a variable to hold more than one type, e.g., string | number, meaning the variable can be a string or a number.
How does JavaScript handle memory?
JavaScript handles memory automatically through a process called garbage collection, where the JavaScript engine frees up memory by removing objects that are no longer reachable or needed in the code.
What are React hooks?
React Hooks are functions that let you use state, lifecycle methods, and other React features in functional components. Examples include useState, useEffect, useContext, useReducer, etc.
How does the Virtual DOM work?
The Virtual DOM is a lightweight copy of the real DOM that React uses to efficiently update the UI. React compares the virtual DOM with the real DOM (reconciliation) and only makes necessary updates, improving performance.
How does the Event Loop work in JavaScript?
The Event Loop is a mechanism in JavaScript that handles asynchronous operations. It continuously checks the call stack and the task queue, processing events and executing callbacks from the queue when the stack is empty.