Running JavaScript in the browser
A free lesson from Swipe Coding · JavaScript, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
Every browser ships with a built-in JavaScript engine, so there's nothing to install to start running JavaScript — you just need a way to get your code onto a page. The most common way is the <script> tag, placed inside an HTML file.
<script>
console.log('Hello from inline JavaScript!');
</script>Writing JavaScript directly inside a <script> tag works fine for tiny experiments, but most real projects keep their JavaScript in a separate file (often named something like script.js) and link it into the HTML instead. This keeps HTML and JavaScript organized and lets the same script be reused across multiple pages.
<script src="script.js"></script>
To link an external JavaScript file to an HTML page, you use a <script> tag with a ____ attribute pointing to the file.
Why do many developers prefer linking an external .js file instead of writing JavaScript directly inside a <script> tag?
Every modern web browser has a built-in JavaScript engine, so users don't need to install anything extra to run JavaScript on a webpage.
You'll often see <script> tags placed near the end of the <body>, right before it closes. That way the browser finishes loading the page's visible content first, before it starts downloading and running the JavaScript.
Keep your streak going in Swipe Coding
Swipe through every level of JavaScript on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →