Skip to main content

Creating hello.js

1

Create a project folder

Open your terminal and create a folder for your practice files:
mkdir js-practice
cd js-practice
2

Create the file

Open this folder in VS Code:
code .
Create a new file called hello.js and add this code:
hello.js
const name = "Sarah";
const language = "JavaScript";

console.log(`Hello, ${name}!`);
console.log(`Welcome to ${language} for Web Dev.`);
console.log("Let's build something.");
3

Run it

Open the integrated terminal in VS Code (Ctrl+`) and run:
node hello.js
Hello, Sarah!
Welcome to JavaScript for Web Dev.
Let's build something.
That’s it. You just wrote and ran a JavaScript program.

What’s happening here

const name = "Sarah";              // Create a variable
console.log(`Hello, ${name}!`);    // Print to the terminal
  • const declares a variable (you’ll learn more in the JavaScript Core section)
  • console.log() prints output to the terminal — JavaScript’s version of Python’s print()
  • Backticks ` with ${} let you embed variables in strings — like Python’s f-strings
const name = "Sarah";
console.log(`Hello, ${name}!`);

Try the browser console

You can also run JavaScript directly in your browser. Open any browser, press F12, and click the Console tab.
// Type this directly in the browser console:
console.log("This runs in the browser!");
2 + 2
// 4
The browser console evaluates expressions immediately and shows the result. You don’t need console.log() for simple expressions — the console shows the return value automatically.
Use the browser console for quick experiments. Use .js files with Node.js for anything you want to save.

What’s next?

You’ve run JavaScript in two places — Node.js and the browser console. Let’s explore the different ways to run JavaScript during development.

Running JavaScript

All the ways to run JavaScript code