Skip to content

Lesson 1 of 50JavaScript basics

The Story of JavaScript

Know where JavaScript came from, who decides what it becomes, and how an engine actually runs your code.

11 min read0/5 questions

HTML gives a page its structure and CSS gives it a look. JavaScript is what makes it respond. JavaScript is the only language every web browser runs, and through Node.js it also runs servers, build tools, desktop apps and the scripts in almost every company's repo. Knowing its history explains its odd corners (and you will meet plenty), and knowing how an engine runs it explains why some code is fast and some is not.

Ten days in 1995

In 1995 the web was static. Pages were documents: text, links, a few images. If you mistyped an email address in a form, you found out only after the whole page went to the server and came back with an error.

Netscape, whose Navigator browser had most of the market, wanted a small scripting language that designers and hobbyists could drop straight into HTML. In May 1995 Brendan Eich wrote the first version in about ten days. It was called Mocha, then LiveScript, and finally JavaScript when it shipped in Netscape Navigator 2.0.

The name was marketing. Sun's Java was the hot new language, and Netscape had a deal with Sun. Apart from some C-style syntax (curly braces, semicolons), the two languages have almost nothing in common. Java is compiled ahead of time and statically typed; JavaScript was interpreted, dynamically typed, and borrowed its ideas from Scheme (functions as values) and Self (prototypes instead of classes).

Quick check
Why is JavaScript called JavaScript?
Need a nudge? A hint rules out a wrong answer.

Ten days is not much time to design a language, and some decisions from that sprint are still with us, because the web never breaks old pages. typeof null returning "object", the loose == operator, and automatic semicolon insertion all date from this era. You will meet each of them in this unit.

A standard and a committee

Microsoft reverse-engineered the language for Internet Explorer 3 in 1996 and called its version JScript. Two browsers with two slightly different languages meant developers wrote everything twice. To stop that, Netscape handed the language to Ecma International, a standards body, and in 1997 the first official spec was published: ECMAScript (standard ECMA-262).

So "JavaScript" is the everyday name and ECMAScript is the name of the specification. The group that evolves it is TC39 (Technical Committee 39): engineers from browser makers, big companies and the community. New features move through stages 0 to 4. A proposal at stage 4 has two shipping implementations and goes into the next yearly edition.

The early years were rocky. ES3 (1999) was solid, then ES4 was so ambitious that the committee abandoned it in 2008. ES5 (2009) added strict mode, JSON, and array methods like map and filter. Then came the big one.

ES2015, often called ES6, was the largest update in the language's history: let and const, arrow functions, classes, modules, promises, template literals, destructuring, Map and Set. Code written before and after 2015 looks like two different languages. Since then TC39 ships a smaller edition every June: ES2017 brought async/await, ES2020 brought ?. and ??, ES2023 brought toSorted, and so on.

JavaScript in milestones
  1. 1995

    JavaScript ships

    Written in about ten days at Netscape, shipped in Navigator 2.0.

  2. 1997

    ECMAScript 1

    Netscape gives the language to Ecma. TC39 owns the spec from now on.

  3. 2005

    Ajax

    Gmail and Google Maps show that pages can fetch data without reloading. JS becomes serious.

  4. 2008

    V8 and Chrome

    A JIT-compiling engine makes JavaScript fast. Every browser races to catch up.

  5. 2009

    Node.js and ES5

    JavaScript leaves the browser. ES5 adds strict mode and JSON.

  6. 2012

    TypeScript

    Microsoft releases a typed superset that compiles to plain JavaScript.

  7. 2015

    ES2015 (ES6)

    let/const, arrows, classes, modules, promises. Yearly releases begin.

  8. 2018–2022

    Deno and Bun

    New runtimes rethink Node: built-in TypeScript, security, speed.

Here is a taste of how ES2015 changed everyday code. Run it, then try changing the name.

JavaScript
// Before 2015var name1 = "Ada";var greeting1 = "Hello, " + name1 + "!"; // After 2015: const, template literals, arrow functionsconst name2 = "Ada";const greet = (who) => `Hello, ${who}!`; console.log(greeting1);console.log(greet(name2));
Output
Press Run (⌘ Enter) to see what happens.
Match the pairs0/4 matched

Match each feature to the edition that introduced it.

Choose an item, then its match on the other side.

Engines and JIT compilation

A JavaScript engine is the program that runs JavaScript. Each major browser has its own:

EngineMade byUsed in
V8GoogleChrome, Edge, Node.js, Deno
SpiderMonkeyMozillaFirefox (descended from Eich's original engine)
JavaScriptCoreAppleSafari, Bun

Early engines were simple interpreters: they read your code and executed it line by line, which was slow. In 2008 Google released Chrome with V8, which used just-in-time (JIT) compilation. The engine starts by interpreting your code quickly, watches which functions run often ("hot" code), and compiles those to native machine code while the program runs. It even makes guesses, like "this function is always called with numbers", and generates code specialised for that guess. If the guess turns out wrong, it throws the fast code away and falls back (a deoptimisation).

That race made JavaScript tens of times faster within a few years, and it is why big apps like Google Docs, Figma and VS Code (an Electron app) are possible at all.

Quick check
A function is called a million times, always with two numbers. What does a JIT engine like V8 do?
Need a nudge? A hint rules out a wrong answer.

The browser and Node.js

The engine alone only understands the language: variables, functions, objects. It has no idea what a web page, a file or a network socket is. Those come from the host environment that embeds the engine.

In a browser, the host adds Web APIs: the DOM (the page's elements), fetch, setTimeout, localStorage, events. In 2009 Ryan Dahl took V8 out of Chrome and wrapped it in a different host, Node.js, which adds files (fs), networking (http), processes and environment variables instead. Suddenly the same language could run a web server. Node's trick was non-blocking I/O: while one request waits on the database, the single JavaScript thread handles others. You will see how in the event loop lesson.

Same engine, different hosts
  1. Your JavaScriptapp.js, the same language in both places
  2. Host APIsBrowser: DOM, fetch, setTimeout. Node: fs, http, process
  3. Event loopBrowser's own loop, or libuv in Node
  4. JS engineV8, SpiderMonkey or JavaScriptCore: parse, interpret, JIT
  5. Operating systemThreads, files, sockets, timers

You write plain JavaScript. const, functions, arrays and objects work the same in Chrome and in Node.

1/4

The runnable code blocks in this course run in a Web Worker, a background browser thread with no page attached. So you have the language plus timers and promises, but no DOM. That is plenty for everything in these units.

JavaScript
// Built into the language: works in any hostconsole.log(typeof Math.max, typeof JSON.parse, typeof Promise); // Provided by the host: timers exist here, the DOM does notconsole.log(typeof setTimeout);console.log(typeof document);
Output
Press Run (⌘ Enter) to see what happens.
Quick check
You run node app.js and get ReferenceError: document is not defined. Why?
Need a nudge? A hint rules out a wrong answer.

npm, new runtimes, and TypeScript

In 2010 npm (the Node package manager) arrived, and with it a culture of small, shared packages. Today the npm registry holds several million packages, and front-end tools like Vite, ESLint and the TypeScript compiler are themselves Node programs installed from it.

Node is no longer the only server-side runtime. Deno (2018, also by Ryan Dahl) fixed what he saw as Node's mistakes: secure by default, built-in TypeScript, web-standard APIs. Bun (1.0 in 2023) runs on JavaScriptCore, is written in Zig, and bundles a package manager, test runner and bundler into one fast binary. All three run the same language; recent Node versions can even run .ts files directly by stripping the types.

TypeScript, released by Microsoft in 2012, is JavaScript plus a static type system. Its compiler checks your types and then erases them, producing plain JavaScript. It became the default for serious projects because large codebases need the safety that dynamic typing does not give you. That is why this track teaches JavaScript first: every TypeScript program is a JavaScript program once the types are gone, so the event loop, closures and this all work exactly as you will learn here.

Put it in order5 steps

Put these events in the order they happened.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.

How this course is laid out

  • JavaScript basics: values, control flow, functions, arrays and objects, the everyday language.
  • JavaScript in depth: closures, this, classes, iterators, errors, modules, Node and testing.
  • JavaScript in the browser: the DOM, events and forms, ending with a to-do app in plain JavaScript.
  • Async JavaScript: the event loop, promises, async/await and talking to real APIs.
  • JavaScript at work: tooling, monorepos, security and performance, the way teams ship.
  • TypeScript: types from the basics to generics, the toolchain, and type safety across the network.

By the end you can build and test a typed browser feature that talks to an API safely, and the course closes with a wrap-up that puts all of it together.

Key terms
ECMAScript
The official specification of JavaScript (ECMA-262), evolved by the TC39 committee with a new edition every year.
ES2015 (ES6)
The 2015 edition that added let/const, arrow functions, classes, modules, promises and more. The start of modern JavaScript.
JS engine
The program that parses and runs JavaScript: V8 (Chrome, Node), SpiderMonkey (Firefox), JavaScriptCore (Safari, Bun).
JIT compilation
Compiling hot code to machine code while the program runs, using runtime observations to specialise it.
host environment
What embeds the engine and adds APIs: the browser (DOM, fetch) or Node.js (fs, http).
Node.js
A runtime (2009) that runs V8 outside the browser with file, network and process APIs.