Your First JavaScript Program
Every JavaScript program you write will use console.log() constantly — it's how your code talks back to you. Let's break down exactly what it does, then run a real program.
The console.log() function
console.log() takes whatever you put inside the parentheses and prints it to the console. Text (called a "string" in programming) needs to go inside quotes — single ('), double ("), or backticks (`) all work, as long as you're consistent.
Comments
Anything after // on a line is a comment — JavaScript ignores it completely. Comments exist purely for humans reading the code later, to explain why something is written the way it is.
Run it yourself
Here's a small program with a comment and two console.log() calls. This was actually executed to get the output shown below — try changing the text and running it yourself using the button under the example.
// This is a comment - JavaScript ignores it
console.log("Hello, World!");
console.log("Welcome to JavaScript.");Hello, World! Welcome to JavaScript.
Notice each console.log() call starts on its own new line automatically — that's its default behavior.
Next: variables — how to actually store and reuse values instead of just printing fixed text.
Practice exercise
Add a comment above your code, then print "Learning JavaScript one step at a time."