What is JavaScript?

The programming language that makes websites interactive.

What is it?

HTML and CSS give you a page of text and images. But on their own, nothing on the page reacts to you when you click, type or scroll.

JavaScript adds that behavior. It's a programming language that runs in your browser and lets a page respond to you: show a menu, check a form, update a price, or load new content without reloading.

It also runs outside the browser: on servers (with Node.js), in mobile apps and even on some hardware. But it's still best known as "the language of the web."

Explain like I'm 10

If HTML is the skeleton of a page and CSS is its clothing, JavaScript is the muscles — it's what makes things actually move.

Examples

A tiny piece of JavaScript

alert("Hello! This popped up because of JavaScript.");

Put this one line in a webpage and it shows a popup box. It's just an instruction the browser understands and runs.

Reacting to a click

const button = document.querySelector("button");

button.addEventListener("click", () => {
  alert("You clicked the button!");
});

This is closer to everyday JavaScript: find a piece of the page, then tell it what to do when the user interacts with it.

How it works

Every browser (Chrome, Firefox, Safari, Edge) has a built-in JavaScript engine. When a page loads, the browser hands the page's JavaScript to this engine, which runs it line by line.

Browser loads page
       ↓
Finds JavaScript code
       ↓
Hands it to the JS engine
       ↓
Engine runs the instructions
       ↓
Page updates / responds

Why does it exist?

Early websites were static: you could read them, but not interact with them. JavaScript lets pages respond to the user right in the browser, without asking a server and reloading the whole page for every small change.

When to use it

Use JavaScript for anything that runs in a browser and reacts to the user right away: checking a form as someone types, updating a page without reloading, or building a whole single-page app. It's also a good fit for the server (via Node.js) if you want one language for client and server.

When not to use it

For CPU-heavy work (video processing, machine learning, low-level system code), languages built for raw speed like C++, Rust or Go usually fit better. A purely informational page with no interactivity may need little or no JavaScript.

Common mistakes

  • Thinking JavaScript and Java are related — they only share part of a name.

  • Assuming JavaScript can only run in a browser. It can also run on servers, in tools, and in scripts.

  • Expecting code changes to show up without saving the file or refreshing the page.

Practice exercises

  1. Easy:

    Open your browser's developer console and run: console.log("Hello, JavaScript").

  2. Medium:

    Use alert() to show a popup, and console.log() to print a message, and explain the difference you notice.

  3. Hard:

    Find one real website feature (autocomplete, a dropdown, a live counter) and describe, in your own words, why it needs JavaScript to work.

Interview questions

What is JavaScript used for?

Making web pages interactive (checking forms, updating content, responding to clicks). Via Node.js, it also builds servers, command-line tools and scripts outside the browser.

Is JavaScript the same as Java?

No. They're unrelated languages with different creators, syntax and uses. Netscape picked the similar name in the 90s as marketing, to ride Java's popularity.

Where does JavaScript code run?

Mostly in a browser's built-in JavaScript engine, but also on servers and in tools via Node.js, and in other runtimes (Deno, Bun, some IoT devices). The language is the same everywhere. What differs is which extra APIs (DOM, file system, etc.) the environment provides.

Is JavaScript compiled or interpreted?

Neither, strictly. Modern engines like V8 use just-in-time (JIT) compilation: code first runs through an interpreter, and code that runs often ("hot" code) is compiled to optimized machine code on the fly. It isn't compiled ahead of time like C++, nor purely interpreted line by line.

What is the relationship between JavaScript and ECMAScript?

ECMAScript is the standard (maintained by the TC39 committee) that defines the language's syntax and behavior. JavaScript is its most common implementation, and the two names are used almost interchangeably. Names like ES6/ES2015 refer to specific yearly releases of the spec.

What is a JavaScript engine? Can you name one?

A program in a browser or runtime that parses and runs JavaScript according to the ECMAScript spec, with its own performance optimizations. The major ones are V8 (Chrome, Node.js), SpiderMonkey (Firefox) and JavaScriptCore (Safari).

Is JavaScript single-threaded?

Yes. The language runs one operation at a time on a single call stack. Apparent concurrency (timers, network requests, clicks) comes from the runtime (the browser's Web APIs, or Node's libuv), which hands finished work back to that one thread through the event loop.

What does it mean that JavaScript is dynamically typed?

A variable's type isn't declared ahead of time and can change while the program runs: let x = 5; x = "now text"; is legal. The type belongs to the value, not the variable.

What does it mean that JavaScript is weakly typed?

Many operations convert values between types automatically instead of raising an error. For example, "5" - 1 becomes 4 because - turns the string into a number first. Handy at times, but a common source of subtle bugs, which is part of why TypeScript exists.

What is Node.js, and how does it differ from JavaScript in a browser?

Node.js runs JavaScript outside the browser. It's built on the V8 engine and adds its own APIs (file system, networking, process control) instead of browser APIs like the DOM. The core language is identical; only the built-in objects around it differ.

What is `"use strict"`, and why would you use it?

A directive that switches a script or function into strict mode. Common mistakes, like assigning to an undeclared variable, then throw errors instead of silently doing the wrong thing. Modules and class bodies are always strict, even without it.

Why is JavaScript described as a multi-paradigm language?

It supports procedural, object-oriented (prototypes and classes) and functional styles (first-class and higher-order functions) without forcing one. A single program can mix all three.

What's the difference between client-side and server-side JavaScript?

Client-side JavaScript runs in the user's browser, changing the page and reacting to user events. Server-side JavaScript (via Node.js) runs on a server and handles databases, files and APIs. Same language; different jobs and available APIs.

Why do teams use tools like Babel or TypeScript alongside plain JavaScript?

Babel converts newer syntax into older JavaScript so it runs in browsers that lack the newest features. TypeScript adds static types checked before the code runs, then compiles to plain JavaScript. Neither replaces JavaScript; both build on it.

Output-prediction: what does `console.log(typeof undeclaredVar)` print if `undeclaredVar` was never declared anywhere?

It logs "undefined" instead of throwing a ReferenceError. typeof is designed to be safe on names that don't exist, one of the few operations that doesn't throw on a missing variable.

Is JavaScript case-sensitive?

Yes. myVariable and myvariable are different names, and keywords must use their exact casing.

Why do some JavaScript files use semicolons and others don't?

Automatic Semicolon Insertion (ASI) adds missing semicolons at line breaks under certain rules, so code without them usually still works. But ASI has edge cases: a line starting with ( or [ can merge with the previous line and silently change meaning. That's why many style guides still write semicolons.

Who created JavaScript, and why does that history come up in interviews?

Brendan Eich created it at Netscape in 1995, reportedly in about ten days. That rush explains several odd design choices (like typeof null being "object") that remain today only for backward compatibility.

What's the difference between "JavaScript" and "ES6"/"ES2015+"?

ES6 (ES2015) is one yearly release of the ECMAScript spec. It added major features like let/const, arrow functions, classes and promises. "JavaScript" means the language as a whole, across all yearly releases.

Can JavaScript run without a browser?

Yes. Node.js, Deno, Bun and various embedded engines all run JavaScript outside a browser.

What's the difference between the DOM and JavaScript itself?

The DOM is the browser's object version of a page's HTML; JavaScript is the language you use to read and change it. The language itself knows nothing about webpages. The browser adds the DOM API on top.

Scenario: a team is choosing between vanilla JavaScript and a framework like React. What does JavaScript itself provide, and what does the framework add?

JavaScript gives you the core language (variables, functions, control flow) and, in the browser, DOM APIs for finding and changing elements by hand. A framework adds a structured way to build UI from reusable components and a more efficient way to update the DOM as data changes. Underneath, it's still plain JavaScript.

Why can the same JavaScript code sometimes behave slightly differently across browsers?

Each browser ships its own engine and its own Web APIs (DOM, fetch, storage). The shared ECMAScript spec keeps core behavior nearly identical, but performance quirks, timing details or missing newer syntax can still cause visible differences.

What is JSON's relationship to JavaScript, given the name?

JSON's syntax comes from JavaScript's object and array literals, but JSON is a language-independent text data format used by nearly every language. It isn't JavaScript code, and parsing it never runs anything.

How does JavaScript's execution model compare to a language like Python's?

Both usually run through an interpreter/JIT rather than full ahead-of-time compilation. But JavaScript was designed to be embedded in a host (a browser or Node.js) and relies entirely on that host for I/O. The spec itself has no built-in way to read a file or make a network request.