Printing
The first thing to learn is printing information. Our program could execute various instructions and calculations, but without printing the results, we would never know if the program works correctly. In JavaScript, we print to the so-called console. The console is a panel that displays messages or errors.
To print to the console, we use the command console.log()
and put what we want to print inside the parentheses. For example:
console.log(4);
This would print 4
to the console. Or:
console.log("Hello, world!");
This would print Hello, world!
to the console.
Note that we place a semicolon ;
at the end. The semicolon indicates the end of a command. While it is not mandatory to write a semicolon at the end of a command in JavaScript, it is recommended to use it. Writing a semicolon will never cause an error, but not writing a semicolon can cause an error.
Also, note that when printing text, we must enclose it in quotation marks, but we do not enclose numbers in quotation marks. We will find out the reason later.
Instructions
In the editor on the right, use the command console.log()
to print your age. Then click the run button.
On the next line, use the console.log()
command again to print your name. Don't forget the quotation marks.
Start programming for free
2/10