Programming language
JavaScript
JavaScript is the ECMAScript language used by browsers and other host environments to work with values, events, modules, and asynchronous tasks.
What is JavaScript and what does it do?
JavaScript is the commonly used name for implementations of the ECMAScript language. It provides values, objects, functions, modules, promises, and rules for executing code. A host environment connects those language features to the outside world. A browser may expose the DOM and web APIs, while another runtime may expose files, processes, or server networking.
A useful mental model keeps the language and its host separate. JavaScript decides how a function, object, or promise behaves. The host decides which external capabilities are available and under which security rules.
One language, different hosts
The same core language can sit inside very different environments.
| Language feature | Host capability |
|---|---|
| Array, object, map, set | DOM collection or database result |
Promise and async function |
Network, file, or timer operation |
| Module syntax | Module loading rules and package resolution |
| Error object | Logging, reporting, and process behavior |
This distinction prevents the assumption that code written for one host can access the same APIs in another. Portable logic stays focused on values; adapters handle the environment.
Asynchronous code still has an order
An async function runs normally until it reaches an await. Its continuation is scheduled for later, even when the awaited promise is already fulfilled.
async function sequence() {
console.log("inside");
await Promise.resolve();
console.log("after await");
}
console.log("before");
sequence();
console.log("after");
The output is before, inside, after, then after await. The example is small, but the same ordering question matters when state changes around several asynchronous operations.
Coercion deserves deliberate rules
JavaScript can convert values automatically. That flexibility is useful at a boundary and dangerous when intent is unclear. A safe baseline is:
- Use
===and!==unless coercion is explicitly part of the rule. - Parse external strings before arithmetic.
- Distinguish a missing value from an empty value.
- Avoid treating every falsy value as the same state.
One visible conversion is easier to review than an implicit conversion that every later reader must reconstruct.
Keeping the boundary clear
JavaScript is a natural fit for browser interaction and can also express services, scripts, and tools in a suitable host. Its dynamic model keeps composition light, but external data can carry the wrong shape deep into a program.
Small functions, runtime validation, focused modules, and behavioral tests keep that risk contained. When a codebase needs static contracts across many boundaries, TypeScript can add earlier feedback. When direct native layout is the central problem, JavaScript is usually not the first layer to choose.