Your First Line of Code
Printing messages with console.log
Welcome! You are about to write your very first piece of code. Do not worry if you have never done this before, we will take it one tiny step at a time.
JavaScript is a language for giving a computer instructions. The computer reads your instructions from top to bottom and does exactly what you say.
Talking to the computer
One of the most useful things you can do is ask the computer to show you a message. In JavaScript we do that with console.log.
The word console just means the little screen where text output appears. The word log means to write something down. So console.log means write this message to the screen.
Here is what it looks like:
console.log("Hello, world!");Let's break that line apart:
console.logis the instruction.- The round brackets
( )hold the thing you want to show. - The text
"Hello, world!"is wrapped in double quotes because it is a piece of text. - The semicolon
;at the end marks the end of the instruction, like a full stop at the end of a sentence.
console.log is how you peek inside your program to see what is going on. You will use it constantly.Try it yourself
Run the starter code and watch your message appear. Then change the words inside the quotes to anything you like and run it again.
Press “Run code” to see the result.
Quick check
Q1 What does console.log do?
Q2 Why is the text wrapped in double quotes in console.log("Hello")?
Want to save your progress? It's free.
Create a free account