Writing and Running Your First Program in JavaScript
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.
Create the file
Save hello.js in an editor — the name before .js can be anything valid for a filename.
Write some code
A console.log call is traditional — it produces visible proof the program ran.
Run it with node
node hello.js in a terminal executes the file top to bottom in order.
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.
console.log("Hello, World!");console.log("This is my first JS program.");Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.