What is JavaScript
Part 1: The Simple Definition
JavaScript is a programming language that lets you add behaviour to web pages. HTML gives a page its structure, CSS gives it its style, and JavaScript makes it come alive — responding to clicks, showing and hiding content, fetching data without reloading, and much more.
Your first JavaScript
Open any browser, press F12, go to the Console tab, and type this:
console.log("Hello, World!");
// Output: Hello, World!
alert("JavaScript is running!");
// Shows a popup in the browserThat's it — you just ran JavaScript. No installation needed. The browser is your runtime.
What makes JavaScript special?
Runs in the browser
Every modern browser (Chrome, Firefox, Safari, Edge) has a built-in JS engine. No installation required by the user.
Also runs on the server
With Node.js, JavaScript runs outside the browser too — powering backends, APIs, and CLI tools.
Interpreted & dynamic
Code is read and executed line by line. You don't need to compile it before running — just save and refresh.
Single-threaded
JavaScript does one thing at a time, but uses an event loop to handle multiple tasks without blocking.
Part 2: What Can You Build With JavaScript?
Frontend — what users see
// Change text on a button click
document.getElementById("btn").addEventListener("click", () => {
document.getElementById("msg").textContent = "You clicked me!";
});
// Fetch data from an API
fetch("https://api.example.com/users")
.then(res => res.json())
.then(data => console.log(data));Backend — server-side with Node.js
// A simple HTTP server with Node.js
const http = require("http");
http.createServer((req, res) => {
res.write("Hello from the server!");
res.end();
}).listen(3000);
console.log("Server running at http://localhost:3000");JavaScript vs Java — clearing the confusion
Despite the similar name, JavaScript and Java are completely different languages. The name was a marketing decision made in 1995 — JavaScript was originally calledMocha, then LiveScript, and renamed to JavaScript to ride the popularity wave of Java. They share nothing in common technically.
// JavaScript — runs in browser, dynamically typed
let name = "Arjun"; // no type annotation needed
name = 42; // can reassign to a different type
// Java — compiled, statically typed
// String name = "Arjun"; // must declare type
// name = 42; // compile error!Part 3: How JavaScript Fits Into a Web Page
A web page is made of three layers. Each has a single job:
HTML — Structure
Defines what's on the page: headings, paragraphs, buttons, images.
<h1>Hello</h1>
<button id="btn">Click me</button>CSS — Style
Controls how it looks: colors, fonts, layout, spacing.
h1 { color: teal; }
button { padding: 8px 16px; }JavaScript — Behaviour
Makes it interactive: responds to events, updates content, talks to servers.
document.getElementById("btn")
.addEventListener("click", () => {
alert("Hi!");
});