1What is the virtual DOM, and how does React update the screen?
The virtual DOM is a lightweight JavaScript description of the UI: plain objects that say "a div with this class containing this text". When state changes, React:
- Calls your components again to produce a new virtual tree.
- Diffs it against the previous tree (reconciliation).
- Commits only the differences to the real DOM.
Why it helps: real DOM operations (layout, paint) are expensive; comparing JS objects is cheap. It also lets you write UI declaratively ("for this state, show this") instead of manually adding and removing nodes.
React's diff uses two assumptions to stay fast (O(n) instead of O(n³)): elements of a different type produce different trees (a div turning into a section is rebuilt), and key props identify which list items are the same across renders.
Strong answer bonus: mention that "virtual DOM is faster than the DOM" is a simplification. Its real value is a simple programming model with good-enough performance by default, and that React Fiber lets React split rendering work into chunks and prioritise urgent updates like typing.