JavaScript for Beginners › Module 1: Getting Started › Lesson 1.1

What Is Programming?

Free previewLesson 1.1 · about 20 minutes · no coding experience needed

JavaScript is built into your browser

Get the full course

13 modules of live, in-browser JavaScript — real code you run yourself, no installs. Lessons 1.1 and 1.2 are free; the rest of the course is Rs. 300 + 18% GST.

Enroll Now — Rs. 354.00

By the end of this lesson you will be able to

  • explain, in your own words, what a computer program is
  • explain why instructions to a computer must be exact and in the right order
  • say what JavaScript is, and why this course teaches it
  • run a piece of code on this website for the first time

A computer only does what it is told

A computer cannot guess what you mean. It cannot use common sense, and it cannot fill in a gap the way a person can. It can only follow instructions, written in a language it understands, one step at a time. A program is simply a list of such instructions.

You give exact instructions all the time without thinking of it as programming. Suppose you asked someone who had never made tea before to make you a cup. You might say:

  1. Boil water in a pan.
  2. Add two spoons of tea leaves.
  3. Let it boil for two minutes.
  4. Add milk and sugar to taste.
  5. Pour through a strainer into a cup.

Every step matters, and so does the order. Add the milk before boiling and you get a different result. Skip the strainer and you get tea leaves in your cup. A computer follows instructions exactly like this: precisely, in order, with no assumptions of its own.

A word you will meet often: code

The instructions a programmer writes are called code, and writing them is called coding. Later in this course you will read words like “program”, “code” and “script” used to mean much the same thing: a set of instructions written for a computer to follow.

Why order and exactness matter

Here are two sets of instructions for crossing a road. Read both before deciding which is safer.

  1. Look both ways
  2. Wait for a gap
  3. Cross

Now the same three instructions, reordered:

  1. Cross
  2. Look both ways
  3. Wait for a gap

The instructions are identical. Only the order changed, and that alone makes the second version dangerous. A person can often notice a badly ordered instruction and correct it. A computer cannot: it will follow the steps precisely as written, in the order given, even into a mistake. This is the single most important idea in programming, and you will see it again in Lesson 1.2, where the order of your instructions decides the order the results appear on the screen.

Which of the two road-crossing lists above would a computer still follow exactly, even though it leads to a bad outcome?

What is JavaScript?

JavaScript is a programming language: a way of writing instructions that a computer can follow. There are many programming languages, in the same way there are many human languages, but JavaScript has a special place among them. It is the language that every web browser understands. Whenever a web page reacts to you (a menu that opens when you tap it, a form that warns you about a missing email address, a map you can drag around), JavaScript is almost certainly doing the work.

It is not only for web pages. The same language also runs on servers, in phone apps and in desktop programs, and it is used by businesses everywhere, from Bombay to Boston.

This course teaches JavaScript for three practical reasons:

JavaScript is not Java

Despite the similar name, JavaScript and Java are two different languages, about as closely related as a car and a carpet. The name was chosen in 1995 mainly for marketing reasons. Everything in this course is JavaScript.

How this course works

This is a text course with no videos, but it is not a course you only read. Every lesson has boxes of real, working JavaScript code, right here on the page. You read them, run them, change them, and see what happens.

Try it now: tap the blue Run button below the box. The result will appear underneath it.

Notice what just happened: nothing was installed, and nothing was sent to any server. Your browser already knows JavaScript, so it simply ran the code and showed you the result. That is how every code box on this course works, from here to the very last lesson.

You do not yet know what that line of code means; that is exactly what Lesson 1.2 teaches, in detail. For now, try changing the words inside the quotation marks to a sentence of your own, and press Run again.

Your code runs in a safe practice area

Each time you press Run, this page sets up a small, sealed-off practice area and runs your code inside it. Your code cannot change this lesson page, cannot see your login, and cannot reach the internet, so you can experiment freely: nothing you type can break anything. If a program accidentally runs for ever, the page stops it after a few seconds and tells you so.

What you will build

Programming is learned by doing, not by reading about it, so this course is built around short, real tasks rather than long explanations. Across the coming lessons in this module you will:

Later modules build on this, through decisions, repetition and small complete projects, and finish with working web pages that respond to clicks and typing. Each lesson assumes only what earlier lessons taught, so if a word is unfamiliar, it will have been explained already or will be explained where it first matters.

Quick check

Three questions to confirm the main ideas before you move on.

1. What is a computer program?

2. Why does the order of instructions matter to a computer?

3. What do you need to install on your own computer to do the exercises in this course?

Summary

  • A program is a list of exact instructions for a computer to follow, one step at a time.
  • A computer cannot guess your meaning or notice a mistake in the order of instructions; it follows them exactly as given.
  • JavaScript is the programming language that every web browser understands. It makes web pages interactive, and it is used far beyond the browser too.
  • Every code box on this course runs real JavaScript in a sealed-off practice area of the page. Nothing needs to be installed, and nothing you type can break anything.

Found a mistake on this page, or something unclear? Report a problem and mention “JavaScript Lesson 1.1”.