What is JavaScript?
JavaScript is the programming language of the web. It runs inside every browser and lets you make pages interactive — respond to clicks, update content, fetch data, animate elements, and much more.
| Technology | Role |
|---|---|
| HTML | Structure — the skeleton |
| CSS | Design — the appearance |
| JavaScript | Behaviour — the interactivity |
Your First JavaScript
<button onclick="greet()">Say hello</button>
<script>
function greet() {
alert("Hello, World!");
}
</script>Where JavaScript Runs
- Browser — built into Chrome, Firefox, Safari, Edge
- Server — Node.js runs JS outside the browser
- Mobile apps — React Native, Capacitor
- Desktop apps — Electron (VS Code is built with it)
Adding JS to a Page
<!-- Inline (small scripts) -->
<script>
console.log("Hello from inline script");
</script>
<!-- External file (recommended) -->
<script src="app.js" defer></script>Use
defer on external scripts — the browser downloads the file in the background and runs it after the HTML is fully parsed. No blocking, no ordering issues.