Skip to content
Getting StartedChapter 3 / 47Beginner4 min read

Setup & First Program

Write your first JavaScript hello world console program. Set up browser DevTools, VS Code and Node.js step by step.

On this page

1. What are setup and the first program?

There are three easy ways to run JavaScript:

  1. Browser console, nothing to install.
  2. A script tag inside an HTML file.
  3. Node.js, running a file from the terminal.

VS Code is the most common editor for writing code.

2. Why does it matter?

While learning, the most important thing is to write code, run it and see the result right away. A good setup makes this cycle fast.

Without a proper setupWith a proper setup
Code in Notepad, no helpAutocomplete and error hints in VS Code
Errors go unnoticedThe console shows the error and line number
Hunting for the page for every testOne command in the terminal to run
Guessing the outputSeeing every value with console.log

3. Where is it used?

MethodWhen to use it
Browser consoleWhen you want to test something small right away
HTML + script fileWhen you are working with a web page
Node.jsWhen you are building scripts, a backend or tools
VS CodeFor writing any kind of code

4. How does it work?

Flow of running your first program
Create a file in VS Code
Write JavaScript code
Run it in the browser or Node.js
See the output in the console

Opening the browser console: In Chrome, right click on the page, choose Inspect, then open the Console tab. Shortcut: Ctrl + Shift + J on Windows, Cmd + Option + J on Mac.

Installing Node.js: Install the LTS version from nodejs.org. Then check the version in the terminal:

bash
node --version
npm --version

5. Code example

Method 1: Browser console. Type this in the console and press Enter:

js
console.log("Hello, World!");

Method 2: HTML file. Create index.html and app.js in a folder:

html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>My first program</title>
    <script src="app.js" defer></script>
  </head>
  <body>
    <h1>I am learning JavaScript</h1>
  </body>
</html>
js
const name = "Ayesha";
console.log("Hello, World!");
console.log(`My name is ${name}`);

Open index.html in the browser and check the console.

Method 3: Node.js. Run the same app.js from the terminal:

bash
node app.js

How does the code work?

ItemMeaning
script src="app.js"Tells the browser to load this JavaScript file
deferThe script runs after the HTML is fully parsed
console.log("...")The text is printed to the console
Backticks and ${name}A template literal, which inserts a variable into text
node app.jsNode.js runs the file in the terminal

Interview tip

The difference between defer and async is asked often. Scripts with defer run in their own order after the HTML is parsed. Scripts with async run as soon as they are downloaded, and the order is not fixed.

6. Common mistakes

Mistake: Putting the script in the head without defer

Why? The script runs before the HTML, the elements do not exist yet, so querySelector returns null.

Better: Add defer to the script tag or use type module, both run after the HTML.

Mistake: Writing the file path wrong

Why? The browser cannot find the file and the console shows a 404 error, so the code never runs.

Better: Check the Network tab or the console and fix the src path relative to the HTML file.

Mistake: Forgetting to open the console

Why? The output of console.log appears in the DevTools console, not on the page. It looks like the code is not working.

Better: Keep DevTools open while you work and read errors right away.

7. What to learn before and after

Final quick revision

PointDetail
EditorVS Code
Quick testBrowser DevTools console
With a web pagescript src + defer
From the terminalnode app.js
Seeing outputconsole.log()