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
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.