Free lesson · What JavaScript Is, and Running Your First Program

Your first program, with nothing installed

You already have a JavaScript engine. It came with your browser. Before installing anything, use it.

Open Chrome, Edge or Firefox and press F12 (or Cmd + Option + I on a Mac). A panel opens. Choose the Console tab. You are looking at a prompt that will run any JavaScript you type.

Type this and press Enter:

2 + 2

It answers 4. You have run a program. It was a short one.

Now something with a visible effect:

console.log("Hello from my first program");

The console prints the text back. console.log is how you make a program tell you something, and you will use it more than any other single thing in this course.

Two different answers on screen

Try both of these in turn and watch carefully:

console.log("Hello");

You will see Hello, and then undefined underneath it.

That is not an error. The console always shows you what an expression evaluated to. console.log printed Hello as its visible effect, and then handed back nothing at all — and "nothing at all" is written undefined in JavaScript. You will meet undefined properly in the next section.

Why the console is worth keeping

Even once you have Node installed and are writing real files, the console stays useful, because it is instant. When you cannot remember whether "5" + 1 gives 6 or "51", the fastest route to certainty is to type it into a console and look.

Do that now, in fact. The answer is one of the most revealing things about the language, and section 2 explains it.

This is one lesson of 60

JavaScript Foundations: The Language, Explained Properly continues from here — 4 lessons are free to read like this one, and the rest come with the course. Enrolled readers also get an AI tutor that has read the lesson they are on.

See the full course

Every free lesson in this course