JavaScript
A programming language that lets web pages respond to clicks, update what users see, and load data without refreshing the page. JavaScript (JS) also runs outside the browser in environments such as Node.js.
Also known as: JS
What JavaScript does on a page
Imagine adding an item to a shopping cart. HTML provides the button and the cart display, and CSS controls how they look. JavaScript can listen for the click, update the cart count, and send the change to a server without reloading the page. Not every interaction needs a script: links, native form submission, and <details> elements already have behavior built into HTML.
The language is not the browser
ECMAScript is the standard that defines the language, including functions, objects, modules, and promises. An engine such as V8 executes the code. The environment the engine runs in supplies additional APIs: browsers expose document so scripts can read and change the Document Object Model (DOM), while Node.js offers APIs such as node:fs for working with files. A script that relies on document won't run unchanged in a typical Node.js process.
JavaScript is dynamically typed: a value has a type, but a variable declared with let can hold a number now and a string later. Functions are values too, so you can pass one to another function to be called later. Objects can inherit properties through a prototype chain, and class syntax builds on that mechanism.
Example: a button that counts clicks
The button appears before the script, so it already exists when querySelector runs. The script registers a function with addEventListener; it doesn't call that function itself. Each click makes the browser call the function, which increments the count and updates the button's text.
<button id="counter">Clicks: 0</button>
<script>
const button = document.querySelector('#counter');
let clicks = 0;
button.addEventListener('click', () => {
clicks += 1;
button.textContent = `Clicks: ${clicks}`;
});
</script>
The handler still has access to the same clicks variable on the next click. That's a closure: the function retains access to variables in the scope where it was created.
Where it runs and what can block it
JavaScript powers browser interfaces, but it's also used for web servers, build tools, and automated tests. React and Vue help build interfaces on top of JavaScript; they're not separate languages. TypeScript adds static type checking, but its type annotations don't validate incoming data at runtime.
When a browser script uses await to wait for a network request, the surrounding async function pauses and the browser can process other work. A long synchronous loop is different: if it runs on the main thread, it can delay both rendering and input handling. Marking the function async doesn't move that loop to another thread.
What to expect in interviews
Expect short snippets about scope, equality, and the order of synchronous code, promise reactions, and timers. Explain why the output occurs rather than just predicting it. For a frontend exercise, you may also be asked to register a DOM event handler or show what a page should display when a request fails.
“JavaScript” questions from real interviews
Asked at 178 companies