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 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() |
You can run JavaScript in three common places: inside the browser console, inside an HTML page using a <script> tag, or outside the browser with Node.js. Beginners usually start in the browser because they can immediately see JavaScript interact with the page.
// 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'When a browser opens a web page, it reads the HTML, builds a document object model called the DOM, applies CSS styles, and then runs JavaScript. JavaScript can read the DOM, change text, add or remove elements, respond to button clicks, validate forms, and request data from APIs.
// HTML: <button id="saveBtn">Save</button>
const button = document.querySelector("#saveBtn");
button.addEventListener("click", function () {
button.textContent = "Saved";
button.classList.add("is-success");
});This is why JavaScript is called the language of the web. HTML gives the page structure, CSS gives it style, and JavaScript adds behavior.
JavaScript runs on a single main thread in the browser. That means one piece of JavaScript code runs at a time. Slow work such as timers, network calls, and user events is handled asynchronously through the event loop, so the browser can stay responsive while waiting for those tasks to finish.
console.log("First");
setTimeout(function () {
console.log("Third");
}, 0);
console.log("Second");
// Output:
// First
// Second
// ThirdThe timer callback runs later, even with a delay of 0, because callbacks wait until the current synchronous code finishes. This same idea is used by events, promises, fetch(), and async/await.
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.
Explore 500+ free tutorials across 20+ languages and frameworks.