JavaScript is the third pillar of the web. If HTML is the skeleton and CSS is the skin, JavaScript is the muscle — it makes things move, respond, and think.
JavaScript is a programming language that runs directly in the browser. It was created in 1995 by Brendan Eich at Netscape, and — famously — was built in just 10 days. Despite its rushed origins, it became the language of the web and today runs on virtually every website on the planet.
Unlike HTML and CSS, which are declarative (you describe what you want), JavaScript is imperative — you write instructions that tell the browser what to do and when to do it.
// HTML describes structure
// CSS describes appearance
// JavaScript describes behaviour
alert("Hello! JavaScript is running.");
In the browser, JavaScript can:
It’s also used outside the browser. Node.js lets JavaScript run on servers, and it powers everything from command-line tools to APIs. But for this course, we focus on JavaScript in the browser.
Every modern browser has a built-in JavaScript engine — Chrome uses V8, Firefox uses SpiderMonkey, Safari uses JavaScriptCore. When the browser loads a webpage, it reads the HTML top to bottom. When it encounters a <script> tag, it pauses and runs the JavaScript before continuing.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My JS page</title>
</head>
<body>
<h1>Hello</h1>
<script>
console.log("JavaScript is running!");
</script>
</body>
</html>
The <script> tag can go in <head> or <body>. Best practice is to place it just before the closing </body> tag — this ensures the HTML is fully loaded before your script tries to interact with it.
Just like CSS, JavaScript can be written inline or in a separate file.
Inline — fine for small snippets:
<script>
console.log("Inline script");
</script>
External file — the preferred approach for anything real:
<script src="script.js"></script>
Keep your JavaScript in a separate .js file. It keeps your HTML clean, lets the browser cache the file, and makes your code far easier to maintain.
Open your browser’s DevTools (F12 or right-click → Inspect), click the Console tab, type the following, and press Enter:
console.log("Hello, world!");
The console is your best friend in JavaScript. Use it to print values, test ideas, and debug problems throughout this course.
| Concept | Detail |
|---|---|
| Created | 1995 by Brendan Eich |
| Runs in | Every modern browser |
| Engine examples | V8 (Chrome), SpiderMonkey (Firefox) |
| Added via | <script> tag or external .js file |
| Best placement | Before closing </body> tag |
| Console shortcut | F12 → Console tab |