JavaScript Introduction

JavaScript is the programming language of the web. Every browser runs it, and with Node.js it runs on servers too — which makes it the only major language that covers an entire application from front to back.

  • Runs everywhere — browsers, servers (Node.js), mobile (React Native), desktop (Electron)
  • Instant feedback — write code, refresh nothing, see results
  • Massive ecosystem — npm hosts millions of packages
  • The web's default — 98%+ of websites use it

Your first program

The classic first step — printing output. In real projects you use console.log() and read the results in the browser's DevTools console:

JavaScript
console.log("Hello, World!");

This box is live — edit the code above and the preview re-runs instantly. Change "friend" to your own name. Break something on purpose: errors show up as a red banner at the bottom of the preview.

How JavaScript reaches the browser

You rarely run JS in isolation — it rides inside HTML via a <script> tag:

HTML
<!DOCTYPE html>
<html>
  <body>
    <h1>My page</h1>
    <script src="app.js"></script> <!-- external file -->
    <script>
      console.log("inline script also works");
    </script>
  </body>
</html>

src="app.js" loads an external file — the standard approach for anything beyond a few lines. Scripts at the end of <body> run after the HTML above them exists, which matters when the code manipulates the page (chapter 5).

Comments

JavaScript
// A single-line comment

/* A multi-line comment
   spans as many lines
   as you need */

What you'll learn

This course builds up in order: values and types → control flow → functions → arrays & objects → the DOM → asynchronous code → modern syntax → error handling. Every concept gets runnable examples you can edit right on the page.

Knowledge Check

4 questions — test your understanding

1

Where can JavaScript run?

2

What does console.log("Hi") do?

3

How do you load an external app.js file into a page?

4

Which of these is a valid single-line comment?