Predict DOM Manipulation Output
Predict Output Easy
Question
What does this code print?
Code
const el = document.createElement("p");
el.textContent = "Hello DOM";
document.body.appendChild(el);
console.log(el.textContent);
Hint
textContent was set before the element was appended.
Explanation
The code creates a <p> element, sets its textContent to "Hello DOM", appends it to the body, then logs the textContent. Since textContent was set before appending, it remains "Hello DOM". The appendChild makes it visible on the page but does not change the textContent.
Related Resources
Related Lessons
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.