All lessons

Your First Program

5 min · JavaScript

Write and run your very first lines of JavaScript, right here on the page.

JavaScript · Your First Program0/5 cleared

Enemy 1 of 5

Every program, no matter how complex it eventually becomes, is a set of instructions the computer follows in order. The simplest instruction of all is: show me a message. That's the traditional first step in any new language, and it's a great way to confirm your code is actually running.

In JavaScript, you print a message with console.log — a built-in function that writes whatever you give it to the console (the output panel here, or the browser's developer console when JavaScript runs on a web page). The text you want to show goes inside the parentheses, wrapped in quotes so JavaScript treats it as literal text rather than trying to interpret it as code, and the line ends with a semicolon.

Press Run to see it. That semicolon at the end of the line marks where one statement ends — JavaScript uses semicolons to separate instructions, similar to how a period ends a sentence, though (unusually) JavaScript can often infer them if you forget, which is a feature called automatic semicolon insertion. It's still good practice to write them explicitly, since relying on that inference has some sharp edges.

You
Binary Treant

Loading editor...

Ln 1, Col 1Spaces: 4
Sign up to fightTarget output: Hello, World!