Skip to content
portfolio/howtos/Learning JavaScript/

Chapter 01

What Is Programming?

A computer is fast and precise, but it has no common sense. It does exactly what you tell it, in the exact order you tell it, and nothing more. Programming is the act of writing those instructions down in a language the computer understands.

Think of a recipe. "Crack two eggs, add a pinch of salt, whisk for thirty seconds." Each step is clear and happens in order. A program is the same idea: a list of small, unambiguous steps. The language we'll use to write them is JavaScript.

Note
You don't need to install anything for this guide. JavaScript already runs inside your web browser. We'll use a built-in tool called the Console as our workbench.

Opening the Console

The Console is a place where you can type one line of JavaScript, press Enter, and instantly see what it does. To open it:

  • Press F12 on your keyboard. (On a Mac you can also use Cmd + Option + J.)
  • A panel opens - this is the developer tools. Click the tab labelled Console.
  • You'll see a blinking cursor. That's where you type.

Leave this page open, open the Console next to it, and type along with every example. Reading code teaches you very little; running it and changing it teaches you everything.

Your First Line of Code

Type this into the Console exactly as shown, then press Enter:

console.log("Hello, world!");

The Console prints:

Hello, world!

Congratulations - you just ran a program. Let's break down what you wrote:

  • console.log is a built-in command that means "print this out so I can see it." It's the tool you'll use most while learning.
  • The round brackets ( ) hold the thing you want to print.
  • The text "Hello, world!" is wrapped in quotes because it's a piece of text, not a command. More on that in Chapter 3.
  • The semicolon ; marks the end of the instruction, like a full stop at the end of a sentence.

Try Changing It

Change the text between the quotes to your own name and run it again:

console.log("My name is Sam");
console.log("I am learning to code");

Notice the two lines run one after the other, top to bottom. That order matters - it's the single most important idea in all of programming. The computer never skips ahead or guesses; it walks down your instructions one at a time.

Notes to Yourself: Comments

Sometimes you want to leave a note in your code for a human to read - not an instruction for the computer. Anything after two slashes // is ignored by JavaScript:

// This is a comment. The computer skips it.
console.log("But this line runs."); // notes can also go at the end

Comments are how you explain your thinking. Use them freely while you're learning.

Tip
If you make a mistake and see a red error message, don't panic - that's completely normal and even experienced programmers see errors constantly. We'll learn how to read them in Chapter 11. For now, just check your quotes and brackets match and try again.