Introduction to JavaScript
Learn what JavaScript is, its history, how it powers the modern web, and why it's the most widely used programming language in the world.
What Is JavaScript?
JavaScript is a high-level, interpreted, dynamically typed programming language. It was originally designed to add interactivity to web pages but has since grown into one of the most versatile languages in existence — running in browsers, on servers, in mobile apps, and even on embedded devices.
Every website you visit almost certainly runs JavaScript. It is the only programming language that runs natively in web browsers, which gives it unmatched reach. Unlike most languages that dominate in a single domain, JavaScript is genuinely full-stack: the same language handles button clicks in the browser and database queries on the server.
A Brief History
JavaScript was created by Brendan Eich at Netscape Communications in just 10 days in 1995. It shipped in Netscape Navigator 2.0 under the name Mocha, then LiveScript, and finally JavaScript — timed to ride the hype of Sun’s Java. Despite its rushed origins, the language has evolved dramatically through a standardization body called ECMA International, which publishes annual updates to the specification.
| Year | Milestone |
|---|---|
| 1995 | Created by Brendan Eich at Netscape |
| 1997 | Standardized as ECMAScript (ES1) by ECMA International |
| 2009 | Node.js released — JS moves to the server |
| 2009 | ES5 — Array.prototype.map, JSON.parse, strict mode |
| 2015 | ES6/ES2015 — the modern JavaScript era begins (classes, arrow functions, modules, Promises) |
| 2020+ | Annual ECMAScript releases; optional chaining, nullish coalescing, top-level await |
The annual release cadence since ES2015 means the language evolves steadily without the decade-long gaps of the early years.
How JavaScript Runs
In the Browser
Every modern browser ships a JavaScript engine. Google Chrome and Node.js both use V8, Mozilla Firefox uses SpiderMonkey, and Safari uses JavaScriptCore. These engines compile JavaScript to native machine code at runtime using JIT (Just-In-Time) compilation, which is why modern JavaScript is fast despite being a dynamically typed, interpreted language.
On the Server — Node.js
In 2009, Ryan Dahl embedded V8 into a C++ runtime called Node.js, giving JavaScript access to the filesystem, network, and OS. This was a turning point: developers could now build both client and server in the same language, sharing code, types, and tooling across the entire stack.
// server.js — a minimal HTTP server in Node.js
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello from Node.js\n');
});
server.listen(3000, () => {
console.log('Server running at http://localhost:3000');
});
Run it with node server.js — no browser required.
Where JavaScript Is Used
JavaScript’s ubiquity means the skills you learn here transfer across many different kinds of projects. The same core language underlies all of these:
- Frontend web — React, Vue, Svelte, vanilla JS for interactive UIs
- Backend / APIs — Node.js with Express, Fastify, or NestJS
- Mobile apps — React Native, Expo (iOS and Android from one codebase)
- Desktop apps — Electron powers VS Code, Slack, Figma, and Discord
- Serverless / edge — Cloudflare Workers, AWS Lambda, Vercel Functions
- Build tooling — Webpack, Vite, ESLint, Prettier — all written in JS/TS
The Ecosystem: npm
npm (Node Package Manager) ships with Node.js and hosts over 2 million packages. It’s the largest package registry in the world, covering everything from full frameworks to tiny utility functions. Understanding npm is essential because almost every real JavaScript project depends on it to manage external libraries.
# Initialize a project
npm init -y
# Install a dependency
npm install express
# Install a dev dependency
npm install --save-dev eslint
# Run a script defined in package.json
npm run build
The package.json file declares your project’s dependencies and scripts — it’s the entry point for any JS project.
Your First JavaScript Programs
Hello World in the browser
The fastest way to run JavaScript is in your browser’s built-in console — no installation needed. Open your browser, press F12, click the Console tab, and type:
console.log("Hello, World!");
A taste of modern JavaScript
This snippet shows the kind of concise, expressive code that modern ES2015+ JavaScript enables. It fetches data from a remote API, extracts the fields you care about, and prints them — all in a few readable lines:
// Fetch users from an API and display their names
const fetchUserNames = async (limit = 5) => {
const response = await fetch(`https://jsonplaceholder.typicode.com/users?_limit=${limit}`);
const users = await response.json();
// Destructure only the fields we need from each user object
return users.map(({ name, email }) => ({ name, email }));
};
fetchUserNames().then(users => {
users.forEach(user => console.log(`${user.name} — ${user.email}`));
});
Even if the syntax is unfamiliar right now, notice how readable it is — fetch some users, pull out their names and emails, print them. That expressiveness is one of JavaScript’s biggest strengths, and you’ll be writing code like this by the end of this series.
JavaScript vs. TypeScript
TypeScript is a typed superset of JavaScript developed by Microsoft. It compiles down to plain JavaScript, so everything you learn here applies directly. You’ll see TypeScript used in most large production codebases because it catches entire classes of bugs at compile time — before you ever run the code. Once you understand JavaScript well, picking up TypeScript is straightforward.
// TypeScript adds type annotations — the runtime behavior is identical
function greet(name: string): string {
return `Hello, ${name}!`;
}
What’s Next
The next tutorial walks through setting up your development environment — installing Node.js, configuring VS Code, and running your first scripts. That’s the foundation for everything that follows.