Interview Questions
Common interview questions with detailed explanations
Class components
More code, larger bundle (also after minification), this context, logic split across multiple methods (componentDidMount/Update/WillUnmount versus useEffect)
createPortal (React)
Portals let your components render some of their children into a different place in the DOM.
what is javascript
requires interpreter?? dynamic, high-level, multi-paradigm, prototype based, single-threaded
enum vs custom enum typeof/ keyof const
enum vs custom enum typeof/ keyof const
Utility types
util types
Type assertion
"as" keyword
any, unknown, never
any, unknown, never
Interface vs Type
Difference between interface and type. Interface can be applied for any object (fn, class, object), can be extended, interfaces with the same name will be merged. Type can be used union/ intersection
console.trace
to check fn
What is virtualization?
What is virtualization?
this
this
Pure function
Pure function - ideal function which determined (for the same input - same output as in math) and without side effects (Interaction with outer environment, increment/ decrement, read/write operations, var/const changes). DOM manipulations, API calls, Timers, external state changes
What are Web Vitals?
Core Web Vitals are metrics that measure user experience: LCP (Largest Contentful Paint), FID (First Input Delay), and CLS (Cumulative Layout Shift). They impact SEO and user satisfaction.
How does Context API works?
Context provides a way to pass data through the component tree without having to pass props down manually at every level. It''s useful for global data like themes, user info, or language preferences.
Explain Flexbox vs Grid
Flexbox is for one-dimensional layouts (row or column). Grid is for two-dimensional layouts (rows and columns). Use Flexbox for navigation bars, Grid for page layouts.
Explain different state management solutions
Local state (useState), Context API (light global state), Redux (predictable state container), Zustand (simple stores), Recoil (atomic state), React Query (server state). Choose based on complexity.
What is Server-Side Rendering (SSR)?
SSR generates HTML on the server for each request, improving SEO and initial load. Next.js supports SSR with getServerSideProps. Contrast with Static Site Generation (SSG) which builds at build time.
Explain the Virtual DOM
The Virtual DOM is a lightweight copy of the actual DOM. React uses it to optimize updates by comparing the virtual DOM with the real DOM and only updating what changed (reconciliation).
What are generics in TypeScript?
Generics allow you to write reusable code that works with multiple types while maintaining type safety. They''re denoted with angle brackets like `<T>` and act as type variables. Parametrized polymorphism
Explain the difference between `interface` and `type`
Interfaces can be extended and merged, making them better for object shapes and classes. Types are more flexible and can represent unions, intersections, and primitives. Prefer interfaces for object shapes.
What are utility types?
TypeScript provides built-in utility types like Partial<T>, Required<T>, Pick<T, K>, Omit<T, K>, Record<K, T>, etc. They help transform types without rewriting them.
What is lazy loading and code splitting?
Lazy loading defers loading of non-critical resources until needed. Code splitting breaks your bundle into smaller chunks loaded on demand, improving initial load time. Use React.lazy() and dynamic imports.
What is the difference between == and === operators?
"==" - converts types before comparing values (5 == "5" → true), "===" - compares both value AND type without conversion