If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Our first program

When we write a computer program, we're giving the computer a set of instructions for what we want it to do. Just like we can tell a dog to "sit" or "beg", we can tell a computer to "add" or "print". A computer isn't as furry as a dog, but fortunately, it's a lot more reliable! And just a bit better at math...
A laptop with a collar and a leash. A speech bubble says "ADD!" on the side. The laptop displays "2 + 2" and "4".
There are many languages we can use to write computer programs. Here on Khan Academy, we'll use our live editing environment with the JavaScript language.
Let's start with a simple "Hello World" program, the first program of many new programmers. Our goal is to get the computer to display "Hello World" somewhere on the screen.
That's as simple as:
println("Hello, World");
Try typing that in the editor below:
If you make any typos or syntax mistakes along the way, our error buddy will pop up and let you know. Everyone makes mistakes while programming, so it's totally okay. That's how we learn and improve!

How does it work?

Now let's break down our 1-line program:
println("Hello, World");
That line of code is called a statement. All programs are made up of statements, and each statement is an instruction to the computer about something we need it to do.
The println() command is also called a function, method, or procedure. That line tells the computer to call the procedure named println that knows how to display output in a console.
The println() procedure expects a single parameter which specifies what text the computer should display. In this program, the value passed in is "Hello, World!", so that is what's displayed.
Display commands are different in each environment and language. The println() command works here, but it may not work in other places. Other ways to display in JavaScript include console.log() and alert(), and you'll find even more ways in other languages like Python, Java, and Snap.

🙋🏽🙋🏻‍♀️🙋🏿‍♂️Do you have any questions about this topic? We'd love to answer— just ask in the questions area below!

Want to join the conversation?