Ready. Start with one instruction.
Loading the learning workspace…
FROM YOUR FIRST INSTRUCTION TO A WORKING APPLICATION
Learn JavaScript from scratch through small working examples, visual experiments and complete projects. No account or AI key required.
Predict → Experiment → Build → Test → Explain
Ready. Start with one instruction.
Loading the learning workspace…
textContent treats a value as text, even if it contains angle brackets. innerHTML parses a string as markup, so untrusted input can create elements or dangerous behavior. Prefer textContent for names, comments and search results. It also replaces existing descendants, so use a dedicated text element if a component contains controls you need to preserve. textContent inserts literal text. It does not parse the string as HTML, which is safer for user-entered text.
document.querySelector('#message').textContent = '<strong>Hello</strong>';Run the preview tests; inspect the live page.
textContent treats a value as text, even if it contains angle brackets. innerHTML parses a string as markup, so untrusted input can create elements or dangerous behavior. Prefer textContent for names, comments and search results. It also replaces existing descendants, so use a dedicated text element if a component contains controls you need to preserve.
document.querySelector('#message').textContent = '<strong>Hello</strong>';Read or update literal text in the selected element. It does not parse user input as HTML.
document.querySelector('#message').textContent = '<strong>Hello</strong>';
console.log(document.querySelectorAll("*").length);Interact with the preview; the diagnostic displays its actual element count.
textContent treats a value as text, even if it contains angle brackets. innerHTML parses a string as markup, so untrusted input can create elements or dangerous behavior. Prefer textContent for names, comments and search results. It also replaces existing descendants, so use a dedicated text element if a component contains controls you need to preserve. textContent inserts literal text. It does not parse the string as HTML, which is safer for user-entered text. The final diagnostic counts actual matching elements. Read querySelectorAll as a selection and length as the collection count.
document.querySelector('#message').textContent = '<strong>Hello</strong>';Read or update literal text in the selected element. It does not parse user input as HTML.
console.log(document.querySelectorAll("*").length);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
document.querySelector('#message').textContent = '<strong>Hello</strong>';
console.log(document.querySelectorAll("button").length);Interact with the preview; the diagnostic displays its actual element count.
textContent treats a value as text, even if it contains angle brackets. innerHTML parses a string as markup, so untrusted input can create elements or dangerous behavior. Prefer textContent for names, comments and search results. It also replaces existing descendants, so use a dedicated text element if a component contains controls you need to preserve. textContent inserts literal text. It does not parse the string as HTML, which is safer for user-entered text. The final diagnostic counts actual matching elements. Read querySelectorAll as a selection and length as the collection count.
document.querySelector('#message').textContent = '<strong>Hello</strong>';Read or update literal text in the selected element. It does not parse user input as HTML.
console.log(document.querySelectorAll("button").length);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
Show the literal text <strong>Hello</strong> without creating a strong element.
// Show the literal text <strong>Hello</strong> without creating a strong element. // Write your JavaScript below.
document.querySelector('#message').textContent = '<strong>Hello</strong>';Assign the exact string to textContent.
Which operation changed the result, why did it work, and what would you test next?
Use a different value that could expose a boundary or mistake. Predict the result first, run it, and explain how the concept would help in a small real application.
Related: Previous lesson Next lesson
100 lessons across 20 modules, covering variables, operators, strings, conditions, loops, functions, scope, arrays, objects, DOM, events, state, testing, asynchronous JavaScript and application development.