Running a .js file
Write your first line of code, run it, and see output in the terminal.
Step 1
The idea
Imagine you're learning to cook and you stick a Post-it note on the counter that says: "I added the salt here."
That note isn't part of the recipe. It's just a message to yourself — a little reminder so you can track what happened.
console.log is exactly that— a Post-it note your program sticks on the screen while it runs. You tell JavaScript what to print, and it prints it in the terminal. That's all it does.
And running a .jsfile? That's just typing one short command in the terminal. Node.js reads your file and executes it top to bottom.
Step 2
See it run
Here is the output you'll see first — so you know what you're aiming for:
Hello, World!
I am learning Playwright.Here is the code that produces it:
console.log("Hello, World!");
console.log("I am learning Playwright.");And here is the one command to run it:
$ node hello.jsconsole.log("Hello")means "print Hello to the terminal." The word "log" comes from keeping a ship's log — writing things down as they happen.Step 3
Now you try
Open VS Code, create a new file called hello.js, and paste this starter code:
console.log("Hello, World!");
console.log("I am learning Playwright.");Now change one thing: replace "Hello, World!" with your own name. For example:
console.log("Hello, Priya!");
console.log("I am learning Playwright.");Save the file. Then open the terminal in VS Code and run:
$ node hello.jsYou should see your name printed in the terminal. That's your first JavaScript program running. Seriously — well done.
Step 4
Why a tester cares
console.logis the first debugging tool every JavaScript developer learns. Here's how it helps you trace what a program is doing step by step:
function processOrder(orderId, quantity, price) {
console.log(`Processing order: ${orderId}`);
const subtotal = quantity * price;
console.log(` Quantity: ${quantity} × Price: ${price} = ${subtotal}`);
const discount = subtotal > 1000 ? subtotal * 0.1 : 0;
console.log(` Discount applied: ${discount}`);
const total = subtotal - discount;
console.log(` Final total: ${total}`);
return total;
}
processOrder("ORD-001", 3, 499);$ node debug-trace.jsProcessing order: ORD-001
Quantity: 3 × Price: 499 = 1497
Discount applied: 149.7
Final total: 1347.3Every line of output tells you exactly what happened and in what order. When something produces the wrong number, you add console.logbefore that step and watch the values — that's debugging.
Recap
- 1console.log prints a message to the terminal — it's your debugging Post-it note.
- 2node hello.js tells Node.js to read and run your file top to bottom.
- 3Add console.log statements at each step to trace what your program is doing — that's debugging.
Up next
Lesson 1.3 — let and const