Setting Up Your Environment
Let’s set up a development environment. This will give you a place to write and run code as you learn.
Installing Node.js
We mentioned that JavaScript can run in browsers and on servers. For learning the language itself, we will use Node.js, a server-side runtime that lets you run JavaScript from the command line.
Node.js is mature, it is well-documented, and it has the largest ecosystem. There are other runtimes, like Deno and Bun, and they have their own advantages, but Node.js is still the standard for learning and for most production use.
Download and Install
- Visit nodejs.org
- Download the LTS (Long-Term Support) version
- Run the installer and follow the prompts
Verify Installation
Open a terminal and run:
node --version
# v22.x.x (or similar)
npm --version
# 10.x.x (or similar)
Node.js comes with npm (Node Package Manager), which you will use to install third-party packages. Alternatives like Yarn and pnpm exist, but npm is sufficient for learning.
Code Editor
You will also want a code editor. We recommend Visual Studio Code (VS Code). It is simple to use and it has good JavaScript support.
- Download from code.visualstudio.com
- Install and launch
Recommended Extensions
Install these from the Extensions panel (Ctrl+Shift+X or Cmd+Shift+X):
ESLint: Identifies and fixes code problemsPrettier: Automatic code formatting
Other popular editors are WebStorm (paid, free for students) and Vim/Neovim, if you prefer to work in the terminal.
Your First JavaScript File
Create a file named hello.js:
const message = "Hello, JavaScript!";
console.log(message);
const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map((n) => n * 2);
console.log(doubled);
Run it from the terminal:
node hello.js
Output:
Hello, JavaScript!
[ 2, 4, 6, 8, 10 ]
You now have a working JavaScript environment.
Running JavaScript in the Browser
You can also run JavaScript directly in a browser. Open any web page, press F12 (or Cmd+Option+I on Mac) to open DevTools, click the Console tab, and type JavaScript code.
For web pages, JavaScript is embedded using the <script> tag:
<script>
console.log("Hello from the browser!");
</script>
This book is about the JavaScript language itself, though, not about browser-specific topics like DOM manipulation or web APIs. Node.js is the simpler setup for that, so we will use it.
Next Steps
Head to Chapter 1 to begin with the basics.