completefrontend
Open lab My progress
THE JAVASCRIPT FIELD GUIDE

Setting up your tools

Install a friendly editor, use the browser console for quick experiments, install Node.js LTS, run a JavaScript file, and know when an online playground is enough.

By the end, you can
  • 01
    Pick the right toolTell apart the editor, the console, the terminal, Node.js, and online playgrounds.
  • 02
    Run a real fileCreate hello.js, run it with node hello.js, and read what it prints.
  • 03
    Fix setup problemsCheck node --version, know why the terminal says "command not found", and restart the terminal after installing.

The tools you need

You need only a few tools to start writing JavaScript. The earlier lessons explained what JavaScript is, where it came from, and what runs it. In this lesson, you set up those tools on your own computer.

Each tool has one main job:

  • The editor is an app where you write code and save it in files.
  • The browser console is a place inside the browser where you type a line of code and see the result at once.
  • The terminal is a window where you type commands for your computer.
  • Node.js is a program that runs JavaScript files outside the browser. You start it from the terminal.
  • An online playground is a website where you write and run code without installing anything.
Four windows. The editor holds hello.js: write and keep files. The console runs 2 + 2: test a quick idea. The terminal runs node hello.js: type commands. The online playground runs a small snippet: share it with a link.editorhello.jswrite and keep filesconsole2 + 2test a quick ideaterminalnode hello.jstype commandsonline playgroundconsole.log("hi")share it with a link
Each tool has one main job. You keep your code in the editor, test tiny ideas in the console, and type commands such as node hello.js in the terminal. A playground is for sharing.
Real-life analogyA workshop for code

A workshop has a different place for each job. You build the table on the workbench. You write a quick measurement on a scratchpad. You switch the machines on at the control panel. You put on a show on a stage. You pick the place that fits the job.

In real life: Workbench
In JavaScript: Editor: write and save files
In real life: Scratchpad
In JavaScript: DevTools console: quick experiments
In real life: Control panel
In JavaScript: Terminal: run commands
In real life: Second stage
In JavaScript: Node.js: run JavaScript outside the browser
Definition

A JavaScript development environment is the set of tools you use to write, run, check, and share JavaScript programs.

VS Code: write and save your code

INTERACTIVE

A code editor is an app for writing code. It is like a text editor, but it understands code. For example, it colors the code and marks many typos. Visual Studio Code (VS Code for short) is a popular free editor. Most other editors look much the same: files on the left, code in the middle, and buttons and status around the edges.

Install VS Code from its official website. Open a folder for your practice files. Then create a file named hello.js. Save often. Node.js can run only a saved file. Text that you typed but did not save is only a draft.

Tour a code editor window
Try it yourself

Editor: This is where you write code you want to keep. VS Code colors the code, matches brackets, and marks many typos before you run the file. Shortcut: Type, then save with Cmd/Ctrl+S.

A simple model of VS Code, made from buttons and labels, not a picture. You can explore it with a keyboard or a screen reader too.

Three shortcuts are worth learning on day one:

  • The Command Palette is a search box for every VS Code action. Press Cmd+Shift+P on Mac or Ctrl+Shift+P on Windows/Linux, then type what you want to do.
  • Quick Open (Cmd/Ctrl+P) jumps to a file by its name.
  • Ctrl+` shows or hides the terminal inside VS Code. The ` key is the backtick, left of 1 on US keyboards. It is the same kind of terminal that you can open from your computer.

The browser console: quick tests

INTERACTIVE

DevTools are tools built into your browser for people who make web pages. One of them is the console. It is the fastest place to ask, "What does this line of code do?" You already used it for 2 + 2 in Why JavaScript?. These habits make it more useful:

  • Enter runs what you typed.
  • Shift+Enter starts a new line without running anything. Use it to write a small program of several lines.
  • The up arrow brings back the commands you typed before.
  • The clear button or console.clear() empties the console.
  • Errors show in red. They often name the file and the line number.
  • $_ gives you the last result. It works only in Chrome and Edge, so don't use it in code you save.
Store a drink, then print itPop out in the code editor (opens in a new tab)JavaScript
const drink = "tea";
console.log("I made " + drink);

A variable is a name that holds a value, so later lines can use it. console.log() prints whatever you put between its round brackets.

  • Line 1 stores "tea" in a variable called drink.
  • Line 2 joins the text "I made " with that value. The console prints I made tea.

Try a quick test like this before you put the same idea in a saved file.

Add two prices in the consolePop out in the code editor (opens in a new tab)JavaScript
const teaPrice = 3;
const snackPrice = 2;
console.log(teaPrice + snackPrice);

Line 1 stores the tea price, 3. Line 2 stores the snack price, 2. Line 3 adds the two numbers and prints 5. The console can check a small sum like this before you use it on a shop's checkout page.

Change a value, then run it againPop out in the code editor (opens in a new tab)JavaScript
const drink = "tea";
console.log(drink.toUpperCase());

Line 1 stores "tea". On line 2, toUpperCase() makes a copy of the text in capital letters, so the console prints TEA. Now change line 1 to "coffee" and run it again. It prints COFFEE. Change one small thing, then run again: this is a good way to test an idea.

Try the console habits
Console inputPop out in the code editor (opens in a new tab)JavaScript
const tool = "console";const note = "Use Shift+Enter for a new line";console.log(tool + ": " + note);
Console outputShift+Enter
console: Use Shift+Enter for a new line
Try it yourself

Press Shift+Enter to add a new line. When the small program is complete, press Enter to run all of it.

A safe model of common console moves. Open the real console in your browser to try them.
The console does not save your work

If you refresh the page or close DevTools, the code you typed in the console can be lost. When an idea matters, move it into a file in your editor.

Installing Node.js

CHECKLIST

Node.js lets you run JavaScript from the terminal. You met it in the Engines, runtimes & hosts lesson. It joins two parts:

  • the V8 engine, which runs JavaScript, and
  • extra tools from Node.js, such as reading and writing files.

For this course, install the LTS version. LTS means "Long-Term Support". It is the stable version that gets fixes for a long time. Most learners and teams should choose it.

  1. Download Node.js LTS from the official Node.js website.
  2. Run the installer. If it asks about PATH, keep the default choice. PATH is the list of folders where your computer looks for commands.
  3. Close the terminal and open it again, so it can find the new node command.
  4. Type node --version and press Enter. Then type npm --version and press Enter.
Example terminal sessionShell
$ node --versionv22.0.0   # example: your LTS version may differ$ npm --version10.0.0    # example: yours may differ$ node hello.jsOpening hello.jsHello, Mina!Ready for the next lesson.

Your version numbers will be different from the example. That is fine. What matters is that both commands print a version, not an error. npm comes with Node.js. It installs packages, which are code that other people wrote and shared, and it runs project scripts. You will use it in later lessons.

A small file Node.js can runPop out in the code editor (opens in a new tab)JavaScript
const tool = "Node";
console.log(tool + " can run this saved file.");

Save this code as check-node.js. Open a terminal in the same folder and run node check-node.js.

  • Line 1 stores the text "Node" in tool.
  • Line 2 joins it with more text and prints Node can run this saved file.

A tiny file like this is a good first test. If it works, you know the node command works before you try a big project.

The table lists three setup commands. Read each row as: when I type this, here is what it checks, what I should see, and what often goes wrong.

What each setup command checks
When you typeWhat does it check?What should you see?What often goes wrong?
node --versionCan the terminal find Node.js?A version number, such as v22....You see command not found or 'node' is not recognized.
npm --versionCan the terminal find npm?A version number.Node.js did not install fully, or the terminal needs a restart.
node hello.jsCan Node.js run your file?The lines your program prints.The terminal is in the wrong folder, the file name is wrong, or the code has a typo.

Running a file

STEP THROUGH

Create a file named hello.js in your practice folder. Node.js runs a file from the first line to the last. The terminal shows only two kinds of things:

  • what the program prints with console.log, and
  • error messages, if something goes wrong.
Run hello.js from top to bottom
Step 0 of 5Ready
Your turn: follow the blue line

This replays node hello.js one line at a time. Guess each terminal line, then step through the file from top to bottom.

Running in
  1. script
Next: line 1
console.log("Opening hello.js");const message = "Hello, " + learner + "!";console.log(message);console.log("Ready for the next lesson.");
CallStoreChangeResultBlue line: runs next. Ran: already executed.
Recent returnsNothing yet. Start with the blue line.
Change line 1: which name should the file greet?

Picking a name starts the replay again from line 1. Guess the second printed line before you step.

A guided replay recorded from real JavaScript calls, not an engine debugger. Step follows executed statements; Back reviews a snapshot. Reset starts a fresh run.

To run the same file yourself, open a terminal in the folder that holds hello.js. Type node hello.js and press Enter.

Left: the editor holds the saved file hello.js. An arrow goes to the terminal. In the terminal you type node hello.js, and it shows three printed lines: Opening hello.js, Hello, Mina!, and Ready for the next lesson.editorhello.jssaved file1. save the fileterminal$ node hello.jsOpening hello.jsHello, Mina!Ready for the next lesson.2. Node.js runs it and prints
You save hello.js in the editor. Then you type node hello.js in the terminal. Node.js reads the saved file from top to bottom. The terminal shows only what console.log prints.

If Node.js says it cannot find the file, check the folder and the spelling of the file name. If it reports a SyntaxError, JavaScript could not read your code. Find the line number in the message, then look at that line in your editor.

Change a saved file and run it againPop out in the code editor (opens in a new tab)JavaScript
const order = "tea";
console.log("Packing " + order);
console.log("Ready");
  • Line 1 stores the order, "tea".
  • Line 2 prints Packing tea.
  • Line 3 prints Ready.

Now change "tea" to "coffee", save, and run the same command again. The terminal now prints Packing coffee. That new line shows that Node.js read the file you just saved.

Left: the editor shows order = coffee, but it is not saved. The saved file still says tea, so the terminal prints Packing tea. Right: the same edit is saved. The saved file says coffee, so the terminal prints Packing coffee.1. edit, not savededitorconst order = "coffee";not saved yetsaved: "tea"Packing tea2. edit, then saveeditorconst order = "coffee";savesaved: "coffee"Packing coffee
Node.js reads the saved file, not the text on your screen. On the left, the change to "coffee" is not saved, so Node.js still prints Packing tea. On the right, you saved first.
Real-life analogyNode.js is a second stage

One actor can perform on two different stages. On the browser stage, the props are buttons, forms, and a page. On the Node.js stage, the props are files, folders, and the terminal.

In real life: Browser stage
In JavaScript: JavaScript can work with a web page
In real life: Node stage
In JavaScript: JavaScript can read files, run tools, and print to a terminal
In real life: Same actor, different props
In JavaScript: Same language, different extra tools
Check for a browser-only tool in Node.jsJavaScript
console.log(typeof document);

Two new words in this line:

  • document is the browser's tool for working with the web page.
  • typeof tells you what kind of value something is. If the name does not exist, it gives "undefined" instead of an error.

Save this line in a file and run it with Node.js. It prints undefined. Node.js has no web page, so it has no document. Paste the same line into the console of a normal web page, and it prints object.

This difference is normal. It shows which program gives you which tools. It does not mean Node.js is installed wrong.

Online playgrounds

PRACTICAL

Sometimes you don't need to install anything. Online playgrounds, such as CodePen, JSFiddle, and StackBlitz, are websites where you write and run code in the browser. They are good for:

  • sharing a small example with someone through a link,
  • testing a tiny idea on a computer that isn't yours, and
  • following a lesson before you have installed your tools.

A playground is run by another company. Never put these into one:

  • passwords, keys, or other secrets,
  • private code from your job, or
  • anything you are not allowed to share.

A playground also can't replace files on your own computer. Real projects need folders, installed packages, terminal commands, and version control (a tool that saves the history of your changes).

A small example that is safe to sharePop out in the code editor (opens in a new tab)JavaScript
const learner = "Asha";
console.log("Shared with " + learner);

Line 1 stores a made-up name, "Asha". Line 2 prints Shared with Asha. Small, harmless examples like this are what playgrounds are good for. Use real private data only in tools your team has approved.

Keep your own copy

Use a playground to try an idea. Don't keep the only copy of your work there. Keep it in files on your own computer.

The edit, save, run loop

STEP THROUGH

You rarely write a whole program in one go. Instead, you repeat a short loop. Make one small change in the editor. Save the file. Run it. Read the first useful line in the terminal. Then make the next small change. Small steps keep mistakes small, so they are easy to find.

A loop of four cards with arrows going round: 1. edit, one change. 2. save, with Cmd or Ctrl+S. 3. run, with node hello.js. 4. read, the first error. Then back to edit.1. edit2. save3. run4. readone changeCmd/Ctrl+Snode hello.jsfirst error
Go round the loop with one small change each time: edit, save, run, and read what the terminal prints. Then start again with the next small change.

The command node hello.js has two parts:

  • node is the program to start.
  • hello.js is the file you give to that program.

The space between them keeps the two parts apart. A terminal command is not JavaScript. It is an instruction for your computer, and you type it in the terminal.

Saving and running are two separate steps. Save after each small edit, so the file on your disk matches the code on your screen. Node.js reads the saved file, not the unsaved text in your editor. If the terminal prints an old message, save the file. Then run node hello.js again before you look for a harder bug.

Read the output from top to bottom, the same way you read the file. Sometimes the command works but prints the wrong greeting. That can mean you changed a different file, or ran the command in a different folder. So check the file name and the folder before you change your JavaScript.

Build the command, then read one result
Step 0 of 5Ready
Your turn: follow the blue line

This replays the edit, save, run loop. Line 2 builds the command as text. The last lines show what a small file can print.

Running in
  1. script
Next: line 1
const command = "node " + file;console.log(command);console.log("Hello from " + file);console.log("Read the result, then edit, save, and run again.");
CallStoreChangeResultBlue line: runs next. Ran: already executed.
Recent returnsNothing yet. Start with the blue line.
Change line 1: which file name should it use?

Picking a file name starts the replay again from line 1. Guess the command on line 2 before you step.

A guided replay recorded from real JavaScript calls, not an engine debugger. Step follows executed statements; Back reviews a snapshot. Reset starts a fresh run.

When a run fails, don't change five things at once. Go in this order:

  1. Check that you saved the file.
  2. Check the file name and the folder the terminal is in.
  3. Read the first error and its line number.
  4. Fix one thing, save, and run the same command again.
What to do when you see an error

An error message is a clue, not a grade. Cannot find module often means the terminal is in a different folder, or the file name is spelled wrong. A SyntaxError means JavaScript could not read the file. Go to the line it names. Look for a missing quote, bracket, or other mark.

Where would you do this?

SORTER

Each tool fits some jobs better than others. Sort each task into the place where you would usually do it. It's fine to move between tools: a quick test in the console often becomes a saved file later.

Pick the right tool for each task
  • Write app.js, which you want to keep and change tomorrow
  • Quickly try 0.1 + 0.2
  • Run node hello.js
  • Share a small program that runs with a friend, without installing anything
  • Rename a folder of practice files
  • Read the red error from a web page you are testing
  • Check whether Node.js is installed with node --version
  • Try a tiny idea on someone else’s computer
Try it yourself
0 of 8 correct

Drag each card, or select it, into the place where you would usually do that task.

Choose a category for every card. You can change an answer at any time; Reset clears them all.

Where you will use this

A normal routine for a beginner looks like this:

  1. Open your course folder in VS Code.
  2. Create or edit a file, such as hello.js.
  3. Save the file.
  4. Open the terminal in that same folder.
  5. Run node hello.js.
  6. Read the output or the errors. Then edit, save, and run again.
Check a to-do message in a filePop out in the code editor (opens in a new tab)JavaScript
const todo = "Save the file";
console.log("Next: " + todo);

Line 1 stores the next task in todo. Line 2 prints Next: Save the file. Later, a real to-do page will show this text on the page. For now, a saved Node.js file is a simple place to check the value and the message first.

You will still use the browser console every day. Use it to test one line, to read an error on a page, or to try a three-line idea with Shift+Enter. Use an online playground when you need a link that someone else can open right away.

Common misconceptions

CLARIFY
  • “VS Code runs JavaScript by itself.” VS Code only edits files. Node.js or a browser runs the code.
  • “The console is only for mistakes.” It is also a place to test ideas and print messages.
  • “npm and Node.js are the same thing.” Node.js runs JavaScript. npm installs packages and runs project scripts.
  • “With online playgrounds, I never need tools on my computer.” Playgrounds are handy, but real projects need folders on your computer and terminal commands.
  • “An error means my setup is broken.” Most errors mean a typo, the wrong folder, or a file you didn't save.

The table compares five tools. Read each row as: this tool is good for one job, and not for another.

Five tools and their jobs
ToolWhat is it good for?What is it not for?
EditorWriting files and keeping them in folders.A quick sum you need once. Use the console.
Browser consoleQuick tests and errors from a web page.Work you want to keep. It is not saved.
TerminalCommands such as node hello.js.Editing many lines of code. Use the editor.
Node.jsRunning JavaScript files outside the browser.Showing a web page on its own.
Online playgroundSharing a quick demo that runs.Private code or secrets.

Practice exercises

5 EXERCISES
Exercise 1 · Warm-upCheck Node.js and npm

Install Node.js LTS if you haven't yet. Then run both version commands. What word describes what each command prints when it works?

Answer, then press Check. Spacing and letter case don’t matter.

    Exercise 2 · Warm-upPredict terminal output

    Read the program. Which two lines does it print?

    Starter codePop out in the code editor (opens in a new tab)JavaScript
    const file = "hello.js";
    console.log("Running " + file);
    console.log("Done");

    Answer, then press Check. Spacing and letter case don’t matter.

      Exercise 3 · PracticeWrite two lines in the console

      In the browser console, write a two-line program. Line 1 stores 0.1 + 0.2 in total. Line 2 prints total.

      Answer, then press Check. Spacing and letter case don’t matter.

        Exercise 4 · PracticeCreate and run hello.js

        Create hello.js, paste in the starter code, and save it. Then run it with Node.js. What greeting does it print?

        Starter codePop out in the code editor (opens in a new tab)JavaScript
        const learner = "Mina";
        console.log("Hello, " + learner + "!");

        Answer, then press Check. Spacing and letter case don’t matter.

          Exercise 5 · ChallengeFind the typo

          This file fails when you run it. Type the fixed second line.

          Starter codePop out in the code editor (opens in a new tab)JavaScript
          const tool = "Node";
          consle.log("Use " + tool);

          Answer, then press Check. Spacing and letter case don’t matter.

            Check your understanding

            7 QUESTIONS
            Lesson quiz · 7 questionsScore: first tries count
            1. Question 1 of 7Which tool is the best place to edit a JavaScript file you want to keep?

              Choose an answer to see the explanation.

            2. Question 2 of 7What does this program print?

              Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
              const file = "hello.js";
              console.log("Running " + file);
              console.log("Done");

              Choose an answer to see the explanation.

            3. Question 3 of 7You installed Node.js, but node --version still says "command not found". What should you try first?

              Choose an answer to see the explanation.

            4. Question 4 of 7In most browser consoles, what does Shift+Enter do while you are typing?

              Choose an answer to see the explanation.

            5. Question 5 of 7Which command asks Node.js to run a file named hello.js?

              Choose an answer to see the explanation.

            6. Question 6 of 7What does this print?

              Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
              const learner = "Mina";
              console.log("Hello, " + learner + "!");

              Choose an answer to see the explanation.

            7. Question 7 of 7When is an online playground the best choice?

              Choose an answer to see the explanation.

            Key takeaways

            • Use an editor, such as VS Code, for code you want to keep.
            • Use the browser console for quick tests and to read errors.
            • Install Node.js LTS, so the node command can run JavaScript files.
            • The terminal runs commands. A command is not the same as JavaScript code.
            • Online playgrounds are good for quick examples you can share. Never put secrets in them.

            A development environment is your editor, console, terminal, Node.js, and sharing tools. Together, they let you write and run programs.

            Coming next: Hello, world! You will run your first code on a web page and from a file.

            CompleteFrontend Clear concepts. Working examples.