Theory Explanation
JavaScript is the language that makes web pages interactive. It runs in every browser and also powers servers, CLIs, desktop apps, mobile apps, and edge functions through runtimes like Node.js, Electron, React Native, Deno, and Cloudflare Workers.
JavaScript is a high-level programming language used to add behavior to web pages. HTML gives the page structure, CSS gives it style, and JavaScript handles logic: responding to clicks, validating forms, fetching API data, updating the DOM, and controlling application state.
The same language also runs outside the browser. Node.js lets JavaScript run on servers and command-line tools, while runtimes such as Deno, Bun, Electron, and React Native use JavaScript for other environments. The core language is standardized as ECMAScript, and each runtime adds its own APIs.
Code Example
JavaScript// Browser or Node.js
const language = "JavaScript";
const yearCreated = 1995;
console.log(language + " was created in " + yearCreated);
// In a browser, JavaScript can also talk to the page.
document.querySelector("h1")?.addEventListener("click", () => {
console.log("The heading was clicked");
});Key Points
- Created by Brendan Eich and standardized as ECMAScript.
- Dynamic typing means values carry types at runtime.
- Functions are first-class values, so they can be passed and returned.
Code Notes
- console.log prints output so you can inspect values while learning.
- The document object exists in browsers, not in plain Node.js.
- The optional chaining operator prevents an error if the h1 does not exist.
Practice Task
Run console.log in the browser console, a Node.js file, and an HTML script tag.
How To Study This
First read the theory, then type the code by hand, change one value, and predict the output before running it. That small loop turns the topic from memorized text into working knowledge.
