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

What a program is, and what JavaScript is for

A program is a list of instructions written down precisely enough that a machine can carry them out without asking you what you meant. That is the whole idea. The difficulty of programming is almost never the typing — it is being precise about something you only half understood.

JavaScript is one language for writing those instructions. It was created in 1995 to make web pages do things, and for a long time that was all it did. Today it also runs servers, build tools, editors and phone apps. The reason to learn it first is simple: it is the only language that runs in every web browser on earth, so if you want to build things people can open by clicking a link, you will meet it eventually.

The language and the place it runs are two different things

This trips up almost every beginner, so it is worth being clear before you write anything.

JavaScript the language gives you variables, arithmetic, functions, arrays, objects, loops. That is what this course teaches, and it is identical everywhere.

The environment is what surrounds the language and gives it something to act on. In a browser, the environment hands you a web page — buttons to react to, text to change. In Node, the environment hands you files on disk and the ability to make network requests. Neither of those is part of JavaScript. They are things JavaScript is given.

When someone says "JavaScript can read files", they mean Node can. When a tutorial's code fails with document is not defined, it is browser code being run in Node. Knowing which half you are in explains most confusing error messages you will meet this year.

Nothing gets compiled

Some languages are turned into a standalone application before anyone runs them, and the translation step catches many mistakes first. JavaScript is not usually one of them. A piece of software called an engine reads your source text and carries it out as it goes.

The practical consequence matters more than the theory: a mistake on line 200 will not be reported when you start the program. It is reported when line 200 runs — which might be ten minutes in, or only when a user clicks a particular button. This is why you will run your code constantly rather than writing a hundred lines and hoping.

The most common engine is V8, built by Google. It is inside Chrome, and it is also inside Node. That is not a coincidence: Node is essentially V8 taken out of the browser and given access to your computer instead of a web page.

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