Running Your First JavaScript Program
Three ways to run JavaScript — the browser console, a script tag, and Node.js.
2 min read
Before writing real programs, it helps to know the three places JavaScript actually runs. All three execute the exact same language — only how you launch the code differs.
The browser console
Every browser ships a JavaScript console built into its developer tools (F12, or right-click → Inspect → Console). Type a line and press Enter, and it runs immediately:
console.log("Hello, world!");This is the fastest way to try something small, but nothing you type there is saved anywhere — it's for experiments, not programs.
A script tag in HTML
To run JavaScript as part of an actual web page, link a .js file from your HTML:
<!DOCTYPE html>
<html>
<body>
<script src="app.js"></script>
</body>
</html>// app.js
console.log("Hello from app.js");Placing the <script> tag near the end of <body> (or adding the defer attribute) ensures the page's HTML has loaded before your script runs and tries to interact with it — important once you start working with the DOM later in this course.
Node.js on the command line
Node.js runs JavaScript outside the browser entirely, which is what makes JavaScript usable for servers, scripts, and build tools. Install Node, save a file, and run it:
node app.jsThere's no HTML involved, and no window or DOM — Node gives you a plain JavaScript runtime plus its own APIs (file system access, networking) suited to server-side work.
console.log is your primary tool
Across all three environments, console.log() is how you inspect what your code is doing — printing values, confirming a function ran, or checking the shape of data:
const name = "Ada";
const age = 36;
console.log(name, age); // Ada 36
console.log({ name, age }); // { name: 'Ada', age: 36 }Logging objects directly (rather than building a string manually) is usually more useful — most consoles let you expand and inspect the structure.
From here, the course moves into the language itself, starting with how JavaScript stores and names values with var, let, and const.