Turning Learners Into Developers
Codekilla
CODEKILLA
back to course
Lesson 02 / 1152%· free preview
Basics2/13

JavaScript Get Started

Run JS in the browser console, or install Node.js for the terminal.

What is JavaScript?

To start writing JavaScript, you need exactly two things:

  1. 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.
  2. 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.

Choose a Runtime
OSRecommended RuntimeInstall
WindowsNode.js LTSnodejs.org installer
macOSNode.js LTSbrew install node
LinuxNode.js LTSsudo apt install nodejs npm (or use nvm)

Verify your install:

bash
node --version
npm --version

You should see something like:

v20.11.0
10.2.4
Your First Node.js Script

Step 1. Create a file hello.js:

javascript
console.log("Hello, Codekilla!");

Step 2. Run it (no compilation step needed — JS is interpreted):

bash
node hello.js
Hello, Codekilla!

That's it. No javac, no g++, no make. Edit → run.

What Just Happened?
  • Node read hello.js from 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.

node vs the browser
WhereJobBuilt-in APIs
BrowserRender pages + run client-side JSDOM, fetch, localStorage, window
Node.jsRun JS on the server / CLIfs, http, process, path

Same language, different host environment. The core syntax is identical.

Useful node Flags
FlagPurpose
node script.jsRun a file
nodeOpen the interactive REPL
node -e "1+1"Evaluate an expression inline
node --watch script.jsAuto-reload on file change (Node 18+)
node --inspect script.jsOpen Chrome DevTools debugger
node --experimental-vm-modulesEnable cutting-edge ESM features

A safe default for learning:

bash
node --watch hello.js
VS Code Setup (recommended)
  1. Install VS Code.
  2. Add the JavaScript and TypeScript Nightly extension (built-in support is already great).
  3. Add ESLint + Prettier for linting + formatting.
  4. Add Code Runner (optional, gives you a one-click ▶ Run button).
  5. Open your folder, create hello.js, hit ▶ — you're coding.
Browser DevTools — The 10-Second Path
  1. Open any web page (yes, this one works).
  2. Press F12 (Windows / Linux) or Cmd + Option + I (macOS).
  3. Click the Console tab.
  4. Type 1 + 1 and press Enter — you'll see 2.
  5. Try console.log("hi") — instant feedback.

This REPL playground is the single fastest way to experiment.

Online Compiler — Skip Setup

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.

Package Manager — npm

Real JS projects use npm (Node Package Manager) — fetches libraries, runs scripts, manages versions:

bash
npm 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.

Common Mistakes
  • Running node hello instead of node hello.js — Node needs the full filename.
  • Forgetting console.log() — typing "hello" alone in a .js file produces no output (unlike a REPL).
  • Mixing require (CommonJS) and import (ESM) in the same project without setting "type": "module" in package.json.
  • Running npm install in the wrong folder — packages land in the current directory's node_modules.
  • Trusting a globally-installed CLI — global versions drift. Prefer npx <tool> so it pulls the project's pinned copy.
Interview Questions

Practice Exercises
  1. First script — Create hello.js with console.log("Hi, " + your_name) and run it via node hello.js. Hint: replace your_name with a string literal.
  2. REPL exploration — Open the Node REPL (node with no args) and try [1, 2, 3].map(x => x * 2). Hint: arrow functions transform array elements.
  3. First package — Run npm init -y, then npm install chalk, then write a script that prints chalk.green("✓ success"). Hint: use import chalk from "chalk" and add "type": "module" to package.json.

💡 Think Like a Programmer: Prefer npx <tool> over npm install -g <tool>. Global installs drift over time and create "works on my machine" bugs. npx always runs the project's pinned version.

AI-powered recap

Quick recap quiz?

We'll generate 5 MCQs from this lesson and check your understanding instantly. Takes ~30 seconds.

# program

Program

JavaScript
console.log("Welcome to JavaScript on Codekilla");
Ready to move on?
// example library
Want more hands-on snippets in JavaScript?
Browse 2 runnable examples · across 1 chapter · short, copy-paste-friendly · grouped by topic
Explore examples
// deep-dive
Go deeper — hand-picked articles
Long-form guides, shortcuts, and mental models that won't fit in a single lesson.
Open Blog
// feedback.matters()
Did this lesson help you?