HTML serialization, is the process of generating an HTML document from an object tree or a structured representation of HTML elements. It involves converting the object-based representation back into a valid HTML string that represents the original document’s structure and content.
In the above implementation we are only serializing the document, there can be further extension on the problem where we are expected to render the tree as well.
The solution to that is also very straight forward, we can simply leverage the el.innerHTML API to write the serialized document on any given parent node.
where documentString is generated from above implementation.