Introduction to JavaScript
What is JavaScript?
JavaScript is the programming language of the web. It's the only language that runs natively in every browser, and it's what makes websites interactive — responding to clicks, validating forms, fetching data, and updating pages without reloading.
If HTML is the skeleton and CSS is the skin, JavaScript is the brain and muscles.
Where JavaScript runs
JavaScript runs in two places:
- The browser — every browser has a JavaScript engine built in (V8 in Chrome, SpiderMonkey in Firefox). This is where most beginners start.
- The server — Node.js lets you run JavaScript outside the browser to build servers, CLI tools, and more.
Your first JavaScript code
Open your browser, press
F12 (or right-click → Inspect), and go to the Console tab. Type this and press Enter:JavaScript
console.log("Hello, JavaScript!");You should see
Hello, JavaScript! printed below. console.log() is JavaScript's way of printing output — you'll use it constantly for debugging.Adding JavaScript to an HTML page
You can add JS to your page using a
<script> tag:HTML
<!DOCTYPE html>
<html>
<head>
<title>JS Demo</title>
</head>
<body>
<h1>My Page</h1>
<script>
console.log("Page loaded!");
document.querySelector("h1").textContent = "Hello from JS!";
</script>
</body>
</html>For real projects, use an external file:
HTML
<script src="app.js"></script>Place it at the end of
<body> or use the defer attribute in <head> so the HTML loads before the script runs.What you'll learn
In the upcoming lessons, we'll cover:
- Variables — storing and naming values
- Functions — reusable blocks of code
- Arrays and objects — organizing data
- DOM manipulation — changing the page with code
- Events — responding to user actions
Strict mode and modern JavaScript
Scripts run in strict mode by default in ES modules (
<script type="module">) and in classes. Strict mode catches silent errors (assigning to undeclared variables, duplicate parameter names) and disables some unsafe legacy features.For classic scripts, enable strict mode at the top of a file:
JavaScript
"use strict";Modern tutorials and frameworks assume strict behavior — another reason to avoid outdated
var patterns.Statements, expressions, and the console
JavaScript code is made of statements (instructions like
const x = 1;) and expressions (values like 2 + 2). The console is your sandbox: try arithmetic, string concatenation, and calling built-in functions:JavaScript
console.log(typeof 42); // "number"
console.log("Hello".length); // 5
console.log(Boolean("")); // falsetypeof helps you inspect values while debugging — you'll use it often before you fully trust what a variable holds.Module scripts vs classic scripts
HTML
<script type="module" src="app.js"></script>Module scripts are deferred by default, run in strict mode, and support
import/export between files. They are the standard for new projects. Classic <script src="app.js" defer> still works for simple pages without a bundler.What makes JavaScript different
JavaScript is dynamically typed (variables don't declare a fixed type) and single-threaded in the browser (one call stack, with async callbacks for waiting on network and timers). It shares syntax ideas with Java, C, and Python but has its own quirks — which the rest of this track covers honestly, including pitfalls like type coercion and asynchronous timing.
Key takeaway
JavaScript is essential for web development. You already have everything you need to start — just open your browser's console and begin experimenting.