JavaScript and the DOM
JavaScript اور DOM
40 min read
Three ways to see it
JavaScript is the only language every web browser in the world can run. It was invented in 10 days in 1995 by Brendan Eich and has since become, for better or worse, the lingua franca of the web. In 2026 it runs on the server too via Node.js, Bun, and Deno, but its native home is the browser. Inside the browser, JavaScript can read and modify the page, listen to user input, talk to servers, and store data in the user's machine. Everything dynamic you have ever seen on the web, from a Daraz add-to-cart animation to a Foodpanda order-tracker map, is JavaScript pushing pixels around.
Way one, the DOM as a tree. When the browser loads an HTML page, it builds a tree in memory called the Document Object Model. Every tag becomes a node. Every attribute, every text fragment, every nested element becomes a child. JavaScript receives this tree through a global object called document. You can read it (document.querySelector('button.send')) and you can modify it (button.textContent = 'Sending...'; button.disabled = true). The visible page is a rendering of this tree, and any change to the tree updates the screen. The DOM is the bridge.
Way two, events. JavaScript runs on events. The browser fires events: click, input, submit, keydown, scroll, load, error. You attach listeners. button.addEventListener('click', sendMoney) means 'when this button is clicked, call sendMoney'. The user tapping Send on Easypaisa is a click event. The form submission to the Telenor server is a submit event. The OTP modal appearing is JavaScript responding to a fetch promise that resolved. Once you internalise the event loop, the entire interactivity story of the web fits into a single mental model.
Quick check
Quick check: what makes modern AI different from a rule-based program?
The why-tree
Why-tree level one: why a programming language in the browser at all? Because pages without interactivity are documents, not applications. A bank statement page is a document. Easypaisa send-money is an application. The line between them is JavaScript.
Try this with Claude
AI-edge prompt to try with Claude: 'Write a vanilla JavaScript module for an Easypaisa-style send-money form. Include input validation for Pakistani mobile numbers (must start with 03 and be 11 digits), amount validation (positive integer, max PKR 25000 per Easypaisa limit), debounced typing, optimistic UI updates, and a graceful network-error retry pattern. No frameworks. Comment every section.' Read the code, do not paste blindly.
Sources
Sources and further reading. MDN, 'JavaScript Guide' and 'Introduction to the DOM'. Eloquent JavaScript by Marijn Haverbeke, free at eloquentjavascript.net. JavaScript.info, complete free curriculum. web.dev, 'Learn JavaScript'. ECMA-262 specification (the language standard). Node.js documentation for the server side. WHATWG HTML Living Standard for the DOM contract.