Back to subject
JavaScript/Introduction to JavaScript

Write Your First Script

Practical lesson

Let's run the smallest useful piece of JavaScript and see exactly what each line does.

<script> opens a block where the browser expects JavaScript instead of HTML. Everything between it and </script> is read as code, not page content.

console.log("Hello from JavaScript!"); sends that text to the developer console a panel most browsers hide by default, opened with F12 or right-click → Inspect. This line changes nothing visible on the page itself.

document.body.innerHTML = "..."; is different: it directly replaces everything inside the page's <body> with new HTML content. This is your first real look at JavaScript changing what a visitor actually sees.

Notice the two lines do two different jobs: one talks to you (the developer, through the console), the other talks to the visitor (by changing the page). Telling these apart is a habit you'll rely on for the rest of this course.

Try it yourself
Code

Starter example

Code
<script>
  console.log("Hello from JavaScript!");
  document.body.innerHTML = "<h1>Check your console!</h1><p>Open dev tools to see the logged message.</p>";
</script>
Live preview