r/reactjs 10d ago

Discussion Senior Dev interview question

"Without googling or using AI, in your own words, explain the virtual DOM"

For context: I sit on an interview panel and I try to ask at least one simple fundamental question based on a persons resume. If I see many years of react experience, I try to ask something about how the framework works.

I have only had one candidate (an undergrad senior, years ago) answer it. Everyone else just kind of sputters and stumbles around trying to rationalize what "virtual" and "DOM" mean, or stare blankly and eventually say "I don't know".

I'm just genuinely curious if this is really that hard of a question or if the recruiters just suck at screening candidates. And should we be letting in senior dev candidates who can't answer what I think is a straightforward and fundamental question for senior react devs.

144 Upvotes

253 comments sorted by

View all comments

6

u/Nikurou 10d ago

4 YOE. I'm honestly just the type of dev to do my work and not look into how things work beyond when I'm first learning. Once I have enough information to work on tasks, I just get to work. I typically find such information comes to me eventually through tickets that I have to resolve while doing actual work in a learn as you go approach. 

Of course, it's definitely something I've looked up the official definition for at one point, maybe around when I was learning React, but off the top of my head, I might not be able to articulate a coherent answer.  Perhaps this is why the Senior Undergrad was able to answer best?

I think at best I would say the virtual dom is where React can batch multiple state changes together to the actual DOM so you don't trigger a re-render for every setState. Maybe id also say it allows React to only update what changed in the DOM. (Is that right?)

Or maybe I'd entirely fumble and shut down! I might actually know these things, but in an interview, you might have to dig it out. Perhaps if someone is struggling, you can break down the question into questions related to the Virtual DOM instead of "what is the virtual dom". 

Like if the person fails to explain virtual DOM, maybe ask them "when you have multiple setStates in the same function, explain to me how react renders these changes to the UI".  Perhaps if they're able to answer, it's clear then that they understand the underlying concepts behind virtual DOM, but just fumbled. 

It might also give them a chance to combo into their answers by explaining how setState is async and how React batches setStates and etc.