Introduction
What is JavaScript?
JavaScript is a lightweight, interpreted, multi-paradigm programming language created by Brendan Eich in 1995 at Netscape. Originally named Mocha, then LiveScript, it was renamed JavaScript as a marketing decision. Today it is the world's most widely used programming language - the only language that runs natively in web browsers.
JavaScript Versions (ECMAScript)
JavaScript is standardized by ECMA International as ECMAScript (ES). Since ES2015 (ES6), new versions are released annually.
| Version | Year | Key Features |
|---|---|---|
| ES5 | 2009 | strict mode, JSON, Array methods (forEach, map, filter) |
| ES6 / ES2015 | 2015 | let/const, arrow functions, classes, modules, promises, template literals |
| ES2016 | 2016 | Array.includes(), exponentiation operator (**) |
| ES2017 | 2017 | async/await, Object.entries(), Object.values() |
| ES2018 | 2018 | rest/spread for objects, Promise.finally(), async iteration |
| ES2019 | 2019 | Array.flat(), Array.flatMap(), Object.fromEntries() |
| ES2020 | 2020 | Optional chaining (?.), nullish coalescing (??), BigInt, Promise.allSettled() |
| ES2021 | 2021 | String.replaceAll(), Promise.any(), logical assignment (&&=, ||=, ??=) |
| ES2022 | 2022 | Array.at(), Object.hasOwn(), class fields, top-level await |
| ES2023 | 2023 | Array.findLast(), Array.toSorted(), Array.toReversed() |
| ES2024 | 2024 | Promise.withResolvers(), Object.groupBy(), Map.groupBy() |
Your First JavaScript Program
// In browser - open DevTools Console (F12) and type:
console.log('Hello, World!');
// In HTML file
// <script src="script.js"></script>
// or inline:
// <script>alert('Hello!');</script>
// Variables
let name = 'Alice'; // mutable
const age = 25; // immutable
var old = 'avoid var'; // function-scoped (legacy)
// Template literals
console.log(`My name is ${name} and I am ${age} years old.`);
// Modern features
const user = { name: 'Bob', address: { city: 'Delhi' } };
console.log(user?.address?.city); // Optional chaining: 'Delhi'
console.log(user?.phone ?? 'N/A'); // Nullish coalescing: 'N/A'JavaScript vs Java
Despite the similar name, JavaScript and Java are completely different languages. JavaScript is dynamically typed, interpreted, and runs in browsers. Java is statically typed, compiled to bytecode, and runs on the JVM. The name similarity was purely a marketing decision in 1995.
- JavaScript was created in 10 days by Brendan Eich in 1995 - originally called Mocha, then LiveScript.
- ECMAScript is the official standard. ES6 (2015) was the biggest update - introduced classes, modules, arrow functions.
- JavaScript is the only language that runs natively in all web browsers.
- Node.js (2009) brought JavaScript to the server - enabling full-stack JS development.
- Use let and const (ES6+) - avoid var which has confusing function-scoping behavior.