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…
Treat an array as data and the DOM as its current presentation. A render function maps each item into an element and replaces the list contents. It should be repeatable: rendering twice must not duplicate rows. Keep user-facing strings as textContent. This small pattern becomes the foundation of searchable lists, task boards and many framework components. Rendering turns source data into elements. Use textContent for text and clear only the region that your component owns.
const names = ['Ada', 'Grace', 'Linus'];
function render() { document.querySelector('#list').replaceChildren(...names.map(name => { const li = document.createElement('li'); li.textContent = name; return li; })); }
render();Run the preview tests; inspect the live page.
Treat an array as data and the DOM as its current presentation. A render function maps each item into an element and replaces the list contents. It should be repeatable: rendering twice must not duplicate rows. Keep user-facing strings as textContent. This small pattern becomes the foundation of searchable lists, task boards and many framework components.
const names = ['Ada', 'Grace', 'Linus'];Declare names with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
function render() { document.querySelector('#list').replaceChildren(...names.map(name => { const li = document.createElement('li'); li.textContent = name; return li; })); }Define a reusable function. Names inside its parentheses are parameters; actual arguments arrive when it is called. Defining the function does not run it.
render();Execute this statement at this point in the program. Follow its arguments and returned value using the surrounding concept explanation.
const names = ['Ada', 'Grace', 'Linus'];
function render() { document.querySelector('#list').replaceChildren(...names.map(name => { const li = document.createElement('li'); li.textContent = name; return li; })); }
render();
console.log(document.querySelectorAll("*").length);Interact with the preview; the diagnostic displays its actual element count.
Treat an array as data and the DOM as its current presentation. A render function maps each item into an element and replaces the list contents. It should be repeatable: rendering twice must not duplicate rows. Keep user-facing strings as textContent. This small pattern becomes the foundation of searchable lists, task boards and many framework components. Rendering turns source data into elements. Use textContent for text and clear only the region that your component owns. The final diagnostic counts actual matching elements. Read querySelectorAll as a selection and length as the collection count.
const names = ['Ada', 'Grace', 'Linus'];Declare names with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
function render() { document.querySelector('#list').replaceChildren(...names.map(name => { const li = document.createElement('li'); li.textContent = name; return li; })); }Define a reusable function. Names inside its parentheses are parameters; actual arguments arrive when it is called. Defining the function does not run it.
render();Execute this statement at this point in the program. Follow its arguments and returned value using the surrounding concept explanation.
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.
const names = ['Ada', 'Grace', 'Linus'];
function render() { document.querySelector('#list').replaceChildren(...names.map(name => { const li = document.createElement('li'); li.textContent = name; return li; })); }
render();
console.log(document.querySelectorAll("button").length);Interact with the preview; the diagnostic displays its actual element count.
Treat an array as data and the DOM as its current presentation. A render function maps each item into an element and replaces the list contents. It should be repeatable: rendering twice must not duplicate rows. Keep user-facing strings as textContent. This small pattern becomes the foundation of searchable lists, task boards and many framework components. Rendering turns source data into elements. Use textContent for text and clear only the region that your component owns. The final diagnostic counts actual matching elements. Read querySelectorAll as a selection and length as the collection count.
const names = ['Ada', 'Grace', 'Linus'];Declare names with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
function render() { document.querySelector('#list').replaceChildren(...names.map(name => { const li = document.createElement('li'); li.textContent = name; return li; })); }Define a reusable function. Names inside its parentheses are parameters; actual arguments arrive when it is called. Defining the function does not run it.
render();Execute this statement at this point in the program. Follow its arguments and returned value using the surrounding concept explanation.
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.
Render Ada, Grace and Linus as list items in that order.
// Render Ada, Grace and Linus as list items in that order. // Write your JavaScript below.
const names = ['Ada', 'Grace', 'Linus'];
function render() { document.querySelector('#list').replaceChildren(...names.map(name => { const li = document.createElement('li'); li.textContent = name; return li; })); }
render();map can create elements, and replaceChildren accepts the spread array.
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.