How to implement DOM like structure tree!? | Frontend Interview Question | Advanced JavaScript
@Yomesh Gupta

Do you see value in our efforts?

Devtools Tech is a free platform for Frontend Engineers. It takes a lot of time, effort, and finanical resources to keep the platform running. If you see any value in our work and would like to support us then you can do using the following options.


In this question, you need to implement the following code so that when the interviewer calls vDocument.render() then the following HTML structure as a string with proper indentation should be returned.

You can also optionally print the output in the console along with returning it.


IMPORTANT: You cannot use actual DOM APIs. You need to implement everything on your own.

const vDocument = new VDocument();
const body = vDocument.createElement("body");
const div = vDocument.createElement("div");

div.innerHTML = "Hello, I am a div!";

// proper html structure 
const html = vDocument.render();


			Hello, I am a div!

You can use spaces or tabs to indent your output. However, test cases check for multiples of 4 spaces per tag level.

This question is designed to test various important topics like OOPS, Inheritance, Candidate's problem solving skills, understanding of DOM, how well the candidate can structure code. So, try to write as clean code as possible.

You can check our answer here.


Start the timer and try to finish as soon as possible. You can record your solving process or take a screenshot of your final code and share it on Twitter/LinkedIn and tag @devtoolstech

Loading IDE...