Setting up your editor

Topic 2 of 4 in Getting started6 min readBeginnerFree course

Overview

You don’t need much to write JavaScript: a browser to run it and an editor to write it. Both are free. This topic gets them ready and shows you the loop you’ll use in every lesson from now on.

The working loop: write and save app.js in the code editor, reload the page in the browser, then read output and errors in the DevTools console — then fix and repeat.

Choose an editor

Any plain-text editor works, but a code editor colours your code, catches typos, completes names for you and helps you move around files. Word processors such as Microsoft Word are not suitable — they add hidden formatting that breaks code.

Visual Studio Code (VS Code) is free, runs on Windows, macOS and Linux, and is what the examples in this course assume. Other good choices are WebStorm, Sublime Text and Zed — the ideas are the same.

Install VS Code

  1. Download it from code.visualstudio.com and run the installer.
  2. Create a folder for this course, for example js-course in your Documents folder.
  3. In VS Code choose File → Open Folder and pick that folder. Keep all your practice files here.
  4. Create a file with File → New File and save it as scratch.js. The .js extension tells VS Code it is JavaScript, so it turns on colours and suggestions.

Useful settings and extensions

A few small changes make a big difference:

  • Format on save. Install the Prettier extension, then turn on Editor: Format On Save in settings. Your code is tidied every time you save — consistent indentation, quotes and semicolons.
  • Auto save. File → Auto Save saves as you type, so you never reload the browser with an old version.
  • ESLint (optional, later). It points out likely bugs, such as a variable you declared but never used.
  • Live Server (optional). It reloads the browser for you whenever you save a file.

Learn three shortcuts now. Ctrl/Cmd + S saves, Ctrl/Cmd + P opens a file by name, and Ctrl/Cmd + / comments out the selected lines.

Open the browser console

Every browser has developer tools (DevTools) with a console where you can type JavaScript and see the result straight away.

  • Chrome / Edge: press Ctrl + Shift + J (or Cmd + Option + J on a Mac).
  • Firefox: press Ctrl + Shift + K (or Cmd + Option + K).
  • Safari: turn on Show features for web developers in Settings → Advanced, then press Cmd + Option + C.

You can also right-click anywhere on a page, choose Inspect, then click the Console tab.

Try it

Type each line and press Enter:

JavaScript
2 + 2
'Java' + 'Script'
Math.max(4, 9, 2)
console.log('Hello from the console');

The console shows the value of each expression straight away. For a multi-line snippet, press Shift + Enter to start a new line without running the code.

Reading errors

Mistakes are normal, and the console tells you exactly what went wrong. Try this typo:

JavaScript
consol.log('oops');
// Uncaught ReferenceError: consol is not defined

An error message has three useful parts: the type of error (ReferenceError), a description (consol is not defined) and — when the code comes from a file — the file name and line number, which you can click to jump straight to the problem.

The console is your scratchpad. Use it to test a line before putting it in a file. If you’re not sure what a piece of code does, paste it in and see.

The other DevTools panels

You’ll use the console most, but it’s worth knowing the neighbours:

Panel What it’s for
Elements (Inspector) See and edit the page’s HTML and CSS live.
Console Run JavaScript, see console.log output and errors.
Sources (Debugger) Read your script files, set breakpoints and step through code.
Network See every file and request the page loads, including fetch calls.
Application (Storage) Inspect localStorage, cookies and other saved data.

You’ll meet the Sources panel properly in the Debugging topic and the Network panel when you start using fetch.

Optional: Node.js

You don’t need Node.js for this course — the browser is enough. But if you’d like to run .js files from a terminal, install the LTS version from nodejs.org, then run:

Terminal
node --version
node scratch.js

Node is also what installs tools such as Prettier and ESLint through npm, which you’ll learn about in the npm and packages topic.

Exercise

Check your setup

Open your browser’s console and run this line. You should see 4 printed below it. Then try console.log('My name is …') with your own name.

JavaScript
console.log(2 + 2);

Summary

  • Any modern browser can run JavaScript — no install needed to start.
  • A code editor like VS Code makes writing larger files much easier.
  • The browser console is the fastest place to try a line of code.
  • You’ll repeat one loop all course: edit and save → reload → read the console.