Chapter 1: Getting Started
Version: JavaScript ES2025 · Node.js 24 LTS
What JavaScript is, the two places it runs, and your first working program — run two different ways before this chapter ends.
What Is JavaScript?
JavaScript is the programming language of the web. Every web browser ships with a JavaScript engine inside it, and that engine is what makes pages respond when you click a button, submit a form, or open a menu. Without JavaScript, a page can show you text and pictures, but it cannot react to you.
Here is the part that surprises many beginners: JavaScript no longer lives only in browsers. A program called Node.js takes the same language and runs it directly on your computer, outside any browser. With Node you can write tools, servers, and scripts that read files and talk to networks. Same language, two homes:
- In the browser — JavaScript runs inside a web page and controls what the page shows and how it behaves.
- On your computer (Node.js) — JavaScript runs from a file, like any other program on your machine, and its output appears in your terminal.
This book teaches one language that works in both places. The first chapters run everything in Node, because Node gives you a clean screen and honest output with nothing else in the way. Later chapters move into the browser and put the same skills to work on real pages.
The same line of code runs in both homes, and both print the same result.
NOTE The version line at the top of this chapter names ES2025, the current edition of the JavaScript standard, and Node.js 24 LTS, the long-term-support release of Node. Every example in this book follows that standard, so what you learn here is the language as it is written today.
Setting Up: Install Node.js
You need exactly one program installed for the first half of this book: Node.js.
- Open your browser and go to the official Node.js website, nodejs.org .
- Download the LTS version for your operating system. LTS means long-term support — it is the stable release meant for learning and for real work.
- Run the installer and accept the default options.
- Open a terminal (Command Prompt or PowerShell on Windows, Terminal on macOS or Linux) and check the install:
node --version Run that in your terminal, not in a file. On the machine used for this book it answers:
v24.20.0 Your numbers may differ slightly. Any version that starts with 22 or 24 is fine for everything in this book. If the terminal says the command is not found, the install did not finish — run the installer once more and open a fresh terminal window.
PRO TIP You also already own the second JavaScript home without installing anything: your browser. Press F12 (or Ctrl+Shift+J) in Chrome, Edge, or Firefox and a panel opens. The Console tab in that panel is a place where you can type JavaScript one line at a time and see answers immediately. You will meet it properly a few sections from now.
Your First Program in Node
Time to make the computer talk. Create a new folder for your practice work, and inside it create a plain text file named hello.js . Type this single line into it:
console.log("Hello, JavaScript!"); Save the file. Open a terminal inside that folder and run:
node hello.js The terminal answers:
Hello, JavaScript! That is a complete, working program. Read the line closely, because you will type its shape thousands of times:
- console.log is a built-in command that means "print what I give you."
- The text inside the quotes — "Hello, JavaScript!" — is a string: a piece of text data. The quotes mark where the text starts and ends; they are not printed.
- The parentheses hold what you hand to the command.
- The semicolon ends the statement, like a full stop ends a sentence.
console is the name for the text screen your program writes to — the terminal when you run under Node, and the Console panel when you run in a browser. console.log writes one line and moves to a fresh line, every time.
Programs Run Top to Bottom
A file can hold many statements. JavaScript runs them in order, first line to last, one at a time:
console.log("My name is Aya.");
console.log("I am learning JavaScript.");
console.log("This line runs third.");
My name is Aya.
I am learning JavaScript.
This line runs third. Three statements, three lines of output, in the exact order written. When a program surprises you later, this is the first thing to check: read it top to bottom and ask what each line does in that order.
Write, run, read. Every program in the early chapters follows this loop.
Watch out for one small thing in that example: everything printed is text, because everything sat inside quotes. Quotes change what a value means. Compare:
console.log(2 + 3);
console.log("2 + 3");
5
2 + 3 Without quotes, 2 + 3 is arithmetic, and JavaScript does the sum. Inside quotes, "2 + 3" is just four characters of text, printed exactly as written. Chapter 2 gives these different kinds of values their proper names.
Your First Program in the Browser Console
Now run the very same code the other way. Open any web page in your browser — a blank new tab is fine — then open the developer tools with F12 and click the Console tab. Click into the empty line at the bottom of the panel, type this, and press Enter:
console.log("Hello, JavaScript!"); The console answers on the line below:
Hello, JavaScript! Same code, same output, different home. The console is a scratchpad: type a line, get an answer, type the next one. It forgets everything when you close or reload the page, which makes it perfect for quick experiments and useless for saving work. Files run by Node are the opposite: saved on disk, run whole, from the first line to the last.
GOTCHA Beginners often mix up the two places. If you type node hello.js into the browser console, you get an error, because the console is already inside JavaScript and node means nothing there. And if you save a file but forget the .js ending, Node will not treat it as your program. Keep the homes straight: terminal commands go in the terminal, JavaScript goes in the file or the console.
Comments: Notes the Computer Ignores
Real programs need notes for the humans reading them. JavaScript gives you comments — text in the file that the engine skips completely. There are two forms:
// This line is a comment. JavaScript skips it completely.
console.log("This line runs."); // A comment can sit after real code too.
/*
A block comment can cover
several lines at once.
*/
console.log("And this line runs as well.");
This line runs.
And this line runs as well. - // starts a single-line comment. Everything after it on that line is ignored.
- /* opens a block comment and */ closes it. Everything between them is ignored, across as many lines as you need.
Comments have three honest uses: explaining why a tricky line exists, leaving a reminder for yourself, and switching a line off temporarily while you test — programmers call that "commenting out." A line that is commented out does not run, which makes comments a safe way to experiment without deleting work.
PRO TIP Write comments that explain why, not what. A comment that says "adds 2 and 3" above console.log(2 + 3) tells the reader nothing the code does not already say. A comment that says "the fee is added here because the receipt must show one total" earns its place.
When Something Goes Wrong
Sooner or later — probably today — you will write a line JavaScript cannot understand, usually a missing quote, bracket, or parenthesis. Node answers with an error message that names the file and the line number, and points a small arrow at the spot it gave up. Read the message from the top: the first line tells you where, and the last line tells you what kind of problem it found. Fix that spot, save, and run again. Every programmer alive does this loop dozens of times a day; the error message is help, not a verdict.
What You Learned
- JavaScript runs in two homes: inside web pages in a browser, and on your computer through Node.js.
- node --version confirms Node is installed; node hello.js runs a saved file.
- console.log(...) prints a line of output.
- Statements run top to bottom, in the order written.
- Quotes turn 2 + 3 from a sum into text.
- The browser console is a scratchpad for one-line experiments; files are for work you keep.
- // and /* ... */ write comments the engine ignores.
Try It Yourself
- Write a program in a file named about-me.js that prints your name on the first line and your city on the
second line. Run it with Node.
Answer
console.log("Name: Rahim");
console.log("City: Dhaka");
Name: Rahim
City: Dhaka Use your own name and city — the shape of the program stays the same.
- This program prints two lines. Change it, without deleting anything, so it prints only the second line:
console.log("You will never see this.");
console.log("Only this line prints."); Answer Put `//` at the start of the first line to comment it out:
// console.log("You will never see this.");
console.log("Only this line prints.");