What Is JavaScript and Where Does It Run?
The only language that runs natively in every browser — and now on servers too
HTML is nouns. CSS is adjectives. JavaScript is verbs. It makes things happen — buttons respond to clicks, forms validate input, pages update without reloading. JavaScript is the language that makes the web feel like an application rather than a document.
The light switch analogy
HTML/CSS is the room. JavaScript is the electricity.
You can have a beautifully decorated room (HTML + CSS) — but without electricity, nothing works. No lights, no appliances, no interactivity. JavaScript is the electricity. It powers all the dynamic behaviour: show this panel when that button is clicked, validate this email address, load more results when the user scrolls down.
Your first JavaScript
Adding JavaScript to an HTML page
<!-- Option 1: inline script tag (small amounts of JS) -->
<script>
alert('Hello from JavaScript!')
console.log('This appears in DevTools')
</script>
<!-- Option 2: external file (recommended for larger projects) -->
<script src="app.js" defer></script>
<!-- defer means: download the JS but don't run it until
the HTML is fully parsed — avoids blocking the page load -->The browser console — your JavaScript playground
Every browser has a built-in JavaScript console. Press F12 (or Cmd+Option+I on Mac), click Console, and type JavaScript directly. This is the fastest way to experiment.
▶ Open the console and try these
Open DevTools and go to the Console tab
F12 → Console
Result
You'll see a > prompt waiting for input
Print a message
console.log("Hello JavaScript")Result
Hello JavaScript
Do some maths
2 + 2 * 5
Result
12 (multiplication happens before addition)
Get today's date
new Date().toLocaleDateString()
Result
"05/06/2026" (or your local format)
See a JavaScript error (on purpose)
undeclaredVariable
Result
ReferenceError: undeclaredVariable is not defined
Try this
Open the console on any website you use regularly. Type document.title in the console — it returns the page's title. Then type document.body.style.background = "red" and watch the background change. You just ran JavaScript on a live website.