Example 1 — Hello, World!
console.log("Hello, World!"); 
This page is a self-contained introduction to JavaScript (JS)—the language that powers interactive websites. You will understand what JavaScript is, how engines run your code, and write your first programs for the browser and console.
Language overview.
Brendan Eich.
Engine & DOM.
First program.
ECMAScript.
Hands-on code.
JavaScript (often shortened to JS) is a popular programming language used for creating interactive and dynamic web content. It is primarily used for front-end web development, allowing developers to add dynamic effects, animations, and functionality to web pages.
JavaScript can also power back-end development through Node.js, build mobile apps with React Native, create games, and even control robots and IoT devices. It is one of the most widely used languages in the world.
Together with HTML (structure) and CSS (style), JavaScript completes the trio of core web technologies. HTML builds the page skeleton; CSS makes it look good; JavaScript makes it do something when users click, scroll, or submit forms.
Learn basic HTML and CSS first, then add JavaScript to change text, respond to clicks, and fetch data. You will see results immediately in the browser.
Brendan Eich is known as the creator of JavaScript. He built the first version in just 10 days in May 1995 while working at Netscape Communications Corporation.
The language was originally called Mocha, then renamed LiveScript, before finally becoming JavaScript. Eich continued to shape the language and later co-founded the Mozilla project. Today JavaScript is standardized as ECMAScript by TC39.
| Version / Event | Year | Highlight |
|---|---|---|
| JavaScript created | 1995 | Brendan Eich, Netscape (10 days) |
| ECMAScript 1 | 1997 | First official standard |
| AJAX era | ~2005 | Dynamic pages without full reloads |
| ES5 | 2009 | Strict mode, JSON support |
| Node.js released | 2009 | JavaScript on the server |
| ES6 / ES2015 | 2015 | let, const, classes, modules, arrow functions |
| Annual releases | 2016+ | ES2016, ES2017, async/await, etc. |
| ES2024 | 2024 | Array grouping, improved RegExp |
When JavaScript runs, the browser or Node.js loads your code into a JavaScript engine (such as V8 in Chrome and Node, or SpiderMonkey in Firefox). The engine parses source code, compiles it to optimized machine code (often via JIT compilation), and executes it.
During execution, the engine manages memory and handles asynchronous work through an event loop—timers, network responses, and user events are queued and processed without blocking the main thread.
In the browser, JavaScript can interact with the Document Object Model (DOM)—a tree representation of HTML—to read and update page content, styles, and event listeners in real time.
JavaScript is generally considered approachable, especially if you have prior programming experience. You can see immediate results in the browser console or with console.log in Node.js.
That said, JavaScript has quirks—type coercion, this binding, and asynchronous patterns—that take time to master. With dedication and practice, becoming proficient is absolutely achievable.
if/for loopsHere is a simple JavaScript program that prints Hello, World! to the console:
console.log("Hello, World!"); Run it with node demo.js in a terminal, or paste the line into your browser’s DevTools Console.
; (optional in many cases, but good habit)' or double " quotes (or backticks for templates)// line or /* block */myVar and myvar are differentfunction name() { } or arrow () => { }You can run JavaScript in three common ways while learning:
node demo.js <script>
console.log("Hello from the browser!");
</script> .js fileYes. JavaScript is standardized as ECMAScript, an open specification maintained by TC39. Implementations—V8, SpiderMonkey, JavaScriptCore—are open-source projects you can read, use, and contribute to.
You do not need a license to write JavaScript. Frameworks and tools built on top (React, Vue, Node.js, Express) are also overwhelmingly open source.
| Concept | What it does |
|---|---|
| Variables | let, const store data |
| Data types | String, number, boolean, object, array, null, undefined |
| Operators | Arithmetic, comparison, logical |
| Control flow | if, else, switch, loops |
| Functions | Reusable blocks of code |
| Objects & arrays | Group related data and methods |
| DOM API | Read and update HTML from JS |
| Async | Promises, async/await, fetch |
| Task | Example |
|---|---|
console.log("Hi"); | |
| Variable | const age = 20; |
| Condition | if (x > 0) { ... } |
| Loop | for (let i = 0; i < n; i++) { ... } |
| Function | function add(a, b) { return a + b; } |
| Select DOM | document.getElementById("msg") |
Seven starter programs. Use View Output to preview here, or open Try It Yourself to edit and run live in the browser.
console.log("Hello, World!"); const name = "Alex";
let age = 20;
const isStudent = true;
console.log(`Name: ${name}`);
console.log("Age:", age);
console.log("Student:", isStudent); Use const for values that won’t be reassigned; use let when the value changes.
function add(a, b) {
return a + b;
}
console.log("Sum =", add(3, 5)); const n = 7;
if (n % 2 === 0) {
console.log(n, "is even");
} else {
console.log(n, "is odd");
} <p id="greeting">Loading...</p>
<button id="btn">Say Hello</button>
<script>
document.getElementById("btn").addEventListener("click", function () {
document.getElementById("greeting").textContent = "Hello, JavaScript!";
});
</script> This is how front-end interactivity works: JavaScript listens for events and updates the DOM.
| Language | Primary use | Best for beginners when… |
|---|---|---|
| JavaScript | Web front-end, Node.js APIs | You want to build interactive websites and full-stack apps |
| Python | Scripts, data science, automation | You prefer readable syntax and data/ML focus |
| Java | Enterprise, Android | You want strong typing and OOP on the JVM |
| HTML / CSS | Structure and styling | You are laying out pages (pair with JS for behavior) |
The browser downloads your page and JavaScript files (inline or external).
V8 or similar parses code, optimizes hot paths, and executes bytecode.
Scripts query the DOM, attach listeners, and respond to clicks and input.
Content updates, animations run, and fetch loads data without full reloads.
console.log("Hello, World!"); in Node or the browser console.const by default; let when reassignment is needed=== over == for comparisonsuserCount, not x)var in new code (prefer let/const)0 == false is trueJavaScript was created by Brendan Eich in just 10 days in May 1995 while he was working at Netscape. The language went through names Mocha and LiveScript before becoming JavaScript—marketing chose the name to ride Java’s popularity, even though the two languages are unrelated.
Edit any example from this page in the live Try It editor.
14 people found this page helpful