Tools Required
You only need two things to start writing JavaScript: a code editor and a browser. Both are free.
- VS Code — the most popular editor for JavaScript. Download at code.visualstudio.com. After installing, add the Live Server extension (by Ritwick Dey) — it lets you run your HTML files with one click.
- Google Chrome — has the best built-in developer tools for debugging JavaScript. Download at google.com/chrome.
- Node.js (optional for now) — lets you run JavaScript outside the browser, directly in your terminal. Download at nodejs.org.
Running JS in the Browser Console
The fastest way to try JavaScript — no files needed. Open Chrome and press the shortcut for your OS to open DevTools:
- Windows / Linux —
F12orCtrl + Shift + J - Mac —
Cmd + Option + J
Go to the Console tab and type directly:
console.log("Hello World");
// Hello World
2 + 3
// 5The console is perfect for quick experiments. Every browser has one.
Internal Script — Hello World
Write JavaScript directly inside an HTML file using the <script> tag. Place it just before the closing </body> tag so the HTML loads first.
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World!</h1>
<script>
console.log("Hello World");
</script>
</body>
</html>Open this file in Chrome, press F12, and go to the Console tab — you will see Hello World printed there.
External Script
For real projects, keep JavaScript in a separate .js file. This keeps your HTML clean and makes the code reusable.
Project folder structure
MyProject/
├── index.html
└── js/
└── script.jsindex.html
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World!</h1>
<script src="js/script.js"></script>
</body>
</html>js/script.js
console.log("Hello World");The src attribute in the script tag points to the external file. The browser downloads and runs it automatically.
Running JS with Node.js
Once Node.js is installed you can run any .js file directly in your terminal — no browser needed.
Windows (Command Prompt or PowerShell)
node js\script.js
# Hello WorldMac / Linux (Terminal)
node js/script.js
# Hello WorldOn Windows use a backslash (\) for folder paths; on Mac/Linux use a forward slash (/). This is how JavaScript runs on servers and in backend applications.
How to Run Your Code
- Live Server (recommended) — right-click
index.htmlin VS Code and select "Open with Live Server". The page opens in Chrome and auto-refreshes on every save. - Double-click the file — open
index.htmldirectly from your file explorer. Works, but won't auto-refresh. - Manually in the browser
- Windows / Linux — press
Ctrl + O, then select yourindex.htmlfile. - Mac — press
Cmd + O, then select yourindex.htmlfile.
- Windows / Linux — press
- Node.js terminal
- Windows — open Command Prompt or PowerShell, navigate to your project folder with
cd path\to\MyProject, then runnode js\script.js. - Mac / Linux — open Terminal, navigate with
cd path/to/MyProject, then runnode js/script.js.
- Windows — open Command Prompt or PowerShell, navigate to your project folder with
Tip: check the Console tab (F12) in Chrome every time you run code — that is where console.log output appears.