Learn JavaScript Hello, JavaScript! — Your First Program

Hello, JavaScript! — Your First Program

⏱ 15 min read
JavaScript is the programming language of the web. It runs directly in every modern browser — Chrome, Firefox, Safari, Edge — without any installation. It is the only language that runs natively in browsers, making it essential for web development.

How JavaScript Works:
JavaScript was created in 1995 by Brendan Eich in just 10 days. Today it powers everything from interactive websites to mobile apps, servers, and even desktop applications.

The browser has a built-in JavaScript engine that reads and runs your code:
Chrome/Edge — V8 engine (the fastest, also used by Node.js)
Firefox — SpiderMonkey engine
Safari — JavaScriptCore engine

Three Ways to Run JavaScript:
1. Browser Console — open DevTools with F12, click "Console", type code and press Enter
2. HTML Script Tag — embed JS directly in a web page
3. Node.js — run JS on the command line outside the browser (covered in the Node.js course)

Writing JavaScript in HTML:
<script src="app.js"></script> — link an external JS file (preferred)
<script>/* inline code */</script> — write JS directly inside HTML (avoid for large projects)

Breaking Down Hello World:
console.log(...) — prints to the browser console (DevTools → Console tab)
This is your most important debugging tool. Use it constantly.

alert(...) — shows a popup dialog box in the browser
document.write(...) — writes text directly into the HTML page

Comments in JavaScript:
// This is a single-line comment
/* This is a multi-line comment */
JavaScript ignores all comments — they are notes for humans only.
Code Example
// Your first JavaScript program
// Open the browser console (F12) to see output

// console.log prints to the console — your #1 debugging tool
console.log("Hello, World!");
console.log("Welcome to JavaScript!");

// Multiple values in one log — separated by commas
const name = "Alice";
const age  = 25;
console.log("Name:", name, "| Age:", age);

// Template literals (backtick strings) — embed variables with ${}
console.log(`Hello, ${name}! You are ${age} years old.`);

// console methods
console.log("Regular message");
console.warn("This is a warning — shows in yellow");
console.error("This is an error — shows in red");
console.table({ name: "Alice", age: 25, city: "Lagos" });

// alert — browser popup (avoid in production code)
// alert("Hello from JavaScript!");

// typeof operator — check what type a value is
console.log(typeof "hello");   // "string"
console.log(typeof 42);        // "number"
console.log(typeof true);      // "boolean"

// JavaScript version check
console.log("JS is running in:", navigator.userAgent);

// Output:
// Hello, World!
// Welcome to JavaScript!
// Name: Alice | Age: 25
// Hello, Alice! You are 25 years old.
← Back to Course Variables, Data Types & Scope →

Log in to track your progress and earn badges as you complete lessons.

Log In to Track Progress