Learn to Program

Programming from scratch, in TJS, in your browser. You need nothing installed and no experience.

If you already program, skip this part and start at Basics, which is written for working developers. If you come from TypeScript, there is also TJS for TypeScript Developers.

TJS is a programming language built on JavaScript, the language every web browser runs. Nearly everything you learn here is also JavaScript, so it carries over to the programs you will meet anywhere on the web. TJS adds checks that catch your mistakes and explain them, which makes it a good first language: when something goes wrong, it tells you.

How the examples work

Every chapter is full of small programs that run on the page. You can change any of them, and the result shows beside the program (or above it, on a phone) as you type. You cannot damage anything: if a change goes badly, the example's undo button or its menu puts the original back.

Most examples end with a test: a few lines that say what the program should do. The line under the result turns green when the program does it and red when it does not, so you can see when you have it right. The first chapter, How This Book Works, shows you all of this before you need it, and Checking Your Work teaches you to write tests of your own.

What you will learn

There are sixteen chapters, starting with How This Book Works. After it, you learn to:

A Calculator puts all of that together into a working pocket calculator. Three chapters follow it:

That is not a watered-down version of programming. Every program you will ever write is made of the same few ideas: values (pieces of information, like numbers and words), names for them, decisions, repetition, lists, things with parts, and functions. Real programs use more of them, in bigger combinations, but nothing fundamentally different.

Some things this part leaves out. Classes (templates for making many similar things) and modules (splitting a program across files) are covered later in this book. Servers (programs that run on another computer, not in the page) are not in this book; the tjs-lang website has a Full Stack section about them. When you finish Tetris, go on to Basics, whose first chapter is Hello TJS. Those chapters are written for people who already program, so they move faster, but by then that is you.

How to read this part

Read the chapters in order. Each one uses what came before, and each is short enough to finish in a sitting.

Do the examples, not just read them. Change a number and see what happens; change it back. Every chapter ends with a few Try it exercises, done in the examples on the page; where an exercise has a test, the test tells you when you have it. If you get stuck, go back to the last example that made sense and change one thing at a time. The exercises matter more than the prose: reading about programming teaches you about as much as reading about swimming.

Expect to make mistakes. Programmers make them all day; the skill is noticing and fixing them quickly. When you make one, TJS tells you what went wrong and where: for example, that you gave it a word where it needed a number. You will see those messages often, and by the end of the part you will read them the way you read a road sign.

For a one-page overview of the whole language, see TJS: Typed JavaScript, the quick start on the tjs-lang website. It is not part of this book and is written for programmers.