What is the virtual DOM? How does it work?

The virtual DOM is a lightweight copy of the actual DOM kept in memory. When changes occur, React updates the virtual DOM first, calculates the differences, and updates only the changed parts in the real DOM, improving performance.