What JavaScript is, where it runs, how to set up your development environment, and writing your first program.
Introduction & Environment Setup
JavaScript is the programming language of the web. Every modern browser runs it, and with Node.js it runs on servers too. This guide takes you from zero to deploying a website on a VPS with nginx - no prior programming experience required.
What is JavaScript?
JavaScript is a high-level, interpreted programming language. That means you write human-readable code and the computer executes it directly - no separate compilation step needed.
Three facts to remember:
- It runs in every browser. Open any website, and JavaScript is powering the interactive parts.
- It runs on servers. Node.js lets you use JavaScript outside the browser.
- It is dynamically typed. You do not need to declare what kind of data a variable holds.
JavaScript was created in 1995 by Brendan Eich at Netscape. Despite the name, it has nothing to do with Java. Today it is one of the most widely used programming languages in the world.
Where JavaScript runs
The browser
Every web browser (Chrome, Firefox, Safari, Edge) has a built-in JavaScript engine:
When you load a web page, the browser reads the HTML, applies the CSS, and executes any JavaScript it finds. This is * client-side* JavaScript.
Node.js
Node.js takes Chrome's V8 engine and runs it outside the browser. This lets you use JavaScript for:
- Web servers
- Command-line tools
- File system operations
- Anything a general-purpose language can do
This is server-side JavaScript.
Which one will we use?
Both. We start with Node.js for learning fundamentals (it is simpler to run a script in the terminal), then move to the browser when we start working with HTML and the DOM.
Setting up your environment
You need three things:
- Node.js - to run JavaScript in the terminal
- A code editor - to write your code
- A web browser - to test browser-based code
Installing Node.js
Go to https://nodejs.org and download the LTS (Long Term Support) version. LTS is the stable, recommended release.
macOS (with Homebrew):
Windows:
Download the .msi installer from nodejs.org and run it. Accept the defaults.
Linux (Ubuntu/Debian):
Verify the installation
Open a terminal and run:
Result:
The exact version number will differ - anything v18 or higher is fine.
Also check that npm (Node Package Manager) is installed:
Result:
Choosing a code editor
Use any editor you like. Popular choices:
If you have no preference, start with VS Code - it is free and has the best JavaScript tooling out of the box.
Using the browser console
Every browser has a built-in JavaScript console. To open it:
- Chrome/Edge:
Ctrl+Shift+J(Windows/Linux) orCmd+Option+J(macOS) - Firefox:
Ctrl+Shift+K(Windows/Linux) orCmd+Option+K(macOS) - Safari: Enable the Develop menu in Preferences → Advanced, then
Cmd+Option+C
Type this into the console and press Enter:
Result:
The console is useful for quick experiments. For anything longer than a few lines, use a file.
Your first JavaScript program
Running JavaScript with Node.js
Create a file called hello.js:
Open a terminal, navigate to the folder containing the file, and run:
Result:
That is it. You just ran your first JavaScript program.
Running JavaScript in the browser
Create a file called index.html:
Open this file in your browser (double-click it or drag it into the browser window). You will see the heading and the paragraph that JavaScript added. Open the console and you will see the log message.
Linking an external script
Inline scripts work, but it is better practice to keep JavaScript in separate files. Create app.js:
Update index.html:
Refresh the page. Same result, but now your JavaScript lives in its own file.
Comments
Comments are notes in your code that JavaScript ignores. Use them to explain why something is done, not what it does.
Result:
Semicolons
JavaScript has automatic semicolon insertion (ASI) - the engine adds semicolons for you in most cases. However, relying on ASI can cause subtle bugs. The convention in this guide is to always use semicolons:
Both produce the same result, but explicit semicolons make your intent clear.
Strict mode
Adding "use strict"; at the top of a file enables stricter parsing and error handling:
Strict mode catches common mistakes like:
- Using undeclared variables
- Assigning to read-only properties
- Duplicating parameter names
Always use strict mode. In modern JavaScript modules (which we will cover later), strict mode is enabled automatically.
How this guide is structured
Each chapter builds on the previous one. Code examples include expected output so you can verify your work. By chapter 12, you will have a website live on the internet.
Summary
- JavaScript runs in browsers (client-side) and in Node.js (server-side).
- Install Node.js LTS to run JavaScript from the terminal.
- Use any code editor - VS Code is a solid default.
console.log()prints output to the terminal or browser console.- Use semicolons and strict mode for cleaner, safer code.
Next up: Variables, Types & Operators - where you will learn how to store and work with data.