JavaScript Get Started
Run JS in the browser console, or install Node.js for the terminal.
To start writing JavaScript, you need exactly two things:
- A JavaScript engine — every modern browser already has one (Chrome's V8, Firefox's SpiderMonkey, Safari's JavaScriptCore). For terminal scripts you also want Node.js.
- A text editor or IDE — VS Code, WebStorm, Sublime Text, or even Notepad.
Good news: you almost certainly already have a JavaScript engine — your browser. You can write your first JS line of code in the next 10 seconds.
| OS | Recommended Runtime | Install |
|---|---|---|
| Windows | Node.js LTS | nodejs.org installer |
| macOS | Node.js LTS | brew install node |
| Linux | Node.js LTS | sudo apt install nodejs npm (or use nvm) |
Verify your install:
bashnode --version npm --version
You should see something like:
v20.11.0
10.2.4
Step 1. Create a file hello.js:
javascriptconsole.log("Hello, Codekilla!");
Step 2. Run it (no compilation step needed — JS is interpreted):
bashnode hello.js
Hello, Codekilla!
That's it. No javac, no g++, no make. Edit → run.
- Node read
hello.jsfrom disk. - The V8 engine parsed your source into an AST (Abstract Syntax Tree).
- V8 JIT-compiled the hot bytecode to native machine code on the fly.
- It executed
console.log, which writes to stdout (the terminal).
You don't compile JS ahead of time the way you do with C++ or Java — the engine does it lazily, the moment your code runs.
| Where | Job | Built-in APIs |
|---|---|---|
| Browser | Render pages + run client-side JS | DOM, fetch, localStorage, window |
| Node.js | Run JS on the server / CLI | fs, http, process, path |
Same language, different host environment. The core syntax is identical.
| Flag | Purpose |
|---|---|
node script.js | Run a file |
node | Open the interactive REPL |
node -e "1+1" | Evaluate an expression inline |
node --watch script.js | Auto-reload on file change (Node 18+) |
node --inspect script.js | Open Chrome DevTools debugger |
node --experimental-vm-modules | Enable cutting-edge ESM features |
A safe default for learning:
bashnode --watch hello.js
- Install VS Code.
- Add the JavaScript and TypeScript Nightly extension (built-in support is already great).
- Add ESLint + Prettier for linting + formatting.
- Add Code Runner (optional, gives you a one-click ▶ Run button).
- Open your folder, create
hello.js, hit ▶ — you're coding.
- Open any web page (yes, this one works).
- Press F12 (Windows / Linux) or Cmd + Option + I (macOS).
- Click the Console tab.
- Type
1 + 1and press Enter — you'll see2. - Try
console.log("hi")— instant feedback.
This REPL playground is the single fastest way to experiment.
Don't want to install anything? Use Codekilla's online JavaScript compiler — write code in the browser, click Run, see output. Perfect for learning on the go.
Real JS projects use npm (Node Package Manager) — fetches libraries, runs scripts, manages versions:
bashnpm init -y # create package.json npm install chalk # add a dependency npm run dev # run a script defined in package.json
The npm registry has 3 million+ packages — the largest on Earth. You'll meet yarn and pnpm later; for now, plain npm is fine.
- Running
node helloinstead ofnode hello.js— Node needs the full filename. - Forgetting
console.log()— typing"hello"alone in a.jsfile produces no output (unlike a REPL). - Mixing
require(CommonJS) andimport(ESM) in the same project without setting"type": "module"inpackage.json. - Running
npm installin the wrong folder — packages land in the current directory'snode_modules. - Trusting a globally-installed CLI — global versions drift. Prefer
npx <tool>so it pulls the project's pinned copy.
- First script — Create
hello.jswithconsole.log("Hi, " + your_name)and run it vianode hello.js. Hint: replaceyour_namewith a string literal. - REPL exploration — Open the Node REPL (
nodewith no args) and try[1, 2, 3].map(x => x * 2). Hint: arrow functions transform array elements. - First package — Run
npm init -y, thennpm install chalk, then write a script that printschalk.green("✓ success"). Hint: useimport chalk from "chalk"and add"type": "module"topackage.json.
💡 Think Like a Programmer: Prefer
npx <tool>overnpm install -g <tool>. Global installs drift over time and create "works on my machine" bugs.npxalways runs the project's pinned version.
Quick recap quiz?
We'll generate 5 MCQs from this lesson and check your understanding instantly. Takes ~30 seconds.
Program
console.log("Welcome to JavaScript on Codekilla");