Episode 3 of 46

Hello World Program in JavaScript

Write your very first JavaScript program — the classic Hello World.

Every programming journey starts with Hello, World! — let's write your first JavaScript program.

Method 1: In the Browser Console

Open Google Chrome, press F12 (or right-click → Inspect), click the Console tab, and type:

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

Press Enter — you'll see Hello, World! printed in the console. That's it! You just ran JavaScript.

Method 2: In an HTML File

Create an index.html file:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Hello JavaScript</title>
</head>
<body>
    <h1>My First JavaScript</h1>

    <script>
        console.log("Hello, World!");
        alert("Hello, World!");
    </script>
</body>
</html>

Three Ways to Output

// 1. Console — for debugging (developer tools)
console.log("Hello from the console!");

// 2. Alert — popup box
alert("Hello from an alert!");

// 3. Document — write directly to the page
document.write("Hello from the page!");

Key Takeaways

  • console.log() is the most common way to output during development
  • alert() shows a popup — useful for quick testing but annoying in practice
  • document.write() writes to the HTML page — rarely used in modern code