03 / JavaScript
The shape of a useful loop
Brendan Eich prototyped JavaScript in ten days at Netscape in 1995. This lesson keeps the loop, a DOM click, and a type check. The terminal will not run the click handler.
JavaScript · 16 min · 0/6 quiz strings accepted
Ten days, then the whole web
In 1995 the web was mostly static HTML. Netscape asked Brendan Eich for a language that would feel adjacent to Java. He designed and prototyped JavaScript in ten days. Prototype-based inheritance and dynamic coercion arrived with that haste.
Google’s V8 engine in 2008, then Ryan Dahl’s Node.js in 2009, untethered the language from the document. Surveys now place adoption between 62.8% and 70.5%. For most working developers, programming still means the web.
Name the value that changes
A useful loop has a counter you can say out loud. let i starts at 0. The condition says when the work is finished. The increment is the only thing that should move i.
If a loop never stops, the condition is lying. Change one comparison, then look again.
for (let i = 0; i < 3; i++) {
console.log(i);
}Ask the document politely
document.querySelector("#start") asks for one element. If it is missing, you get null — evidence, not a crash you should ignore.
Do not walk the whole DOM looking for a private node. Give the control an id or a role and select that.
Check the type before you trust it
Records arrive messy. Before you render a name, ask whether it is a string. typeof record.name === "string" is a small, honest gate.
if (typeof record.name === "string") {
title.textContent = record.name;
}Beginner curriculum: a counted click
The report’s first JavaScript module selects an element, counts clicks, and binds a listener. CodeLabs will not fire that listener. Type the selection and the bind exactly.
const displayElement = document.getElementById("output-display");
let clickCount = 0;
function handleInteraction() {
clickCount++;
displayElement.innerText = `You have engaged the DOM ${clickCount} times.`;
}
document.getElementById("action-btn").addEventListener("click", handleInteraction);Intermediate: fetch is a string, not a request
The report’s next tier uses async/await and fetch. This lab will not call a network. Remember the shape; do not expect a JSON payload.
Glossary
- condition
- The test that decides whether a loop or branch continues.
- querySelector
- A safe way to ask the document for one matching element.
- typeof
- An operator that reports the kind of a value.
- V8
- Google’s JavaScript and WebAssembly engine, in Chrome and Node.js.
Quiz
Type the string. Keep the understanding.
The terminal cannot execute this language. It only prints ACCEPTED or REJECTED when your string matches the lesson.