Learn JavaScript
❯ getting_started.first_program

Writing and Running Your First Program in JavaScript

$concept

A JavaScript program is plain text saved with a .js extension — no project scaffolding, no compiler. You write code in an editor, save the file, and hand it to node from a terminal, which executes it top to bottom exactly once, then exits.

In the browser the same code runs inside a page (via a script tag) or pasted into the console. Either way there is no build step between writing and running — save, execute, see output — which makes the feedback loop the fastest of any mainstream language.

$how it works
1

Create the file

Save hello.js in an editor — the name before .js can be anything valid for a filename.

2

Write some code

A console.log call is traditional — it produces visible proof the program ran.

3

Run it with node

node hello.js in a terminal executes the file top to bottom in order.

4

Read errors top-down

Runtime errors print the message plus file and line — fix the first error first, since later ones often cascade from it.

$example
console.log("Hello, World!");
console.log("This is my first JS program.");
Output
Hello, World!
This is my first JS program.
1Line 1 calls console.log with a string, printing Hello, World!.
2Line 2 prints the second message on its own line.
3node hello.js executes both lines in order — nothing happens until you run the file.
$use cases
The classic setup check on a new machine or Node install
A scratch file for testing syntax before using it in a project
Small automation scripts that start exactly this way
Minimal reproductions when asking for help or filing issues

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself — building beats watching.