Interview Questions · ReactJs ReactJs

Why does React use a Virtual DOM instead of directly manipulating the real DOM on every update?

Practice question from Interview Questions (ReactJs ReactJs), with the correct answer and a step-by-step solution.

easy · MCQ · Q-1CA205

Why does React use a Virtual DOM instead of directly manipulating the real DOM on every update?

Figure 1 for the question
  1. A.Because the real DOM cannot be updated programmatically at all
  2. B.To batch and minimize expensive real DOM operations by diffing lightweight in-memory trees firstCorrect answer
  3. C.Because browsers do not allow JavaScript to read the DOM
  4. D.To permanently replace the real DOM so the browser never renders HTML

Solution

Direct, unbatched DOM manipulation is slow because layout and paint can be triggered on every change; consider how diffing before touching the DOM helps.

More from Interview Questions

All of Interview Questions

Practise more ReactJs

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed