CoursePart 1 — JavaScript for PlaywrightLesson 1.2
Lesson 1.2Part 1 — JavaScript for Playwright

Running a .js file

Write your first line of code, run it, and see output in the terminal.

Lesson 1.2of 24
Next

Step 1

The idea

01

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

02

Here is the output you'll see first — so you know what you're aiming for:

Output
Hello, World!
I am learning Playwright.

Here is the code that produces it:

hello.js
console.log("Hello, World!");
console.log("I am learning Playwright.");

And here is the one command to run it:

Terminal
$ node hello.js
💡Tip
console.log— "console" is the terminal window, and "log" means print. So console.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

03

Open VS Code, create a new file called hello.js, and paste this starter code:

hello.js
console.log("Hello, World!");
console.log("I am learning Playwright.");

Now change one thing: replace "Hello, World!" with your own name. For example:

js
console.log("Hello, Priya!");
console.log("I am learning Playwright.");

Save the file. Then open the terminal in VS Code and run:

Terminal
$ node hello.js

You should see your name printed in the terminal. That's your first JavaScript program running. Seriously — well done.

🎉Win!
If you see your name in the terminal, you just ran JavaScript on your computer. The same engine that powers millions of websites just followed your instructions.

Step 4

Why a tester cares

04

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:

debug-trace.js
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);
Terminal
$ node debug-trace.js
Output
Processing order: ORD-001
  Quantity: 3 × Price: 499 = 1497
  Discount applied: 149.7
  Final total: 1347.3

Every 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

3 key points
  • 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.