JavaScript began as a way to add interactivity to web pages, but it now runs in browsers, servers, and mobile and desktop apps. ECMAScript is the name used for its official specification. The language keeps evolving; whether a feature works depends on the runtime that executes it. section 1.0 section 1.1.2
A runtime supplies both an engine, which turns JavaScript into instructions the CPU can run, and APIs for its host environment. Browser APIs can fetch data, handle user events, and update the DOM; Node.js APIs can work with sockets, files, and subprocesses. Code that relies on a host API may therefore need a particular runtime, even when the JavaScript itself is valid elsewhere. section 1.1.1
Familiar syntax can hide unfamiliar rules:
- Functions are first-class objects: they can be stored in variables, passed as arguments, and created by other functions. JavaScript also connects functions with closures. section 1.1
- Objects use prototypes. Even classes, introduced in ES2015, operate according to the rules for functions and prototypes rather than replacing them. section 1.1 section 9.4
- JavaScript code runs in a single thread; callbacks and promises help handle asynchronous operations, while workers can delegate work outside the main thread. section 1.1
- Ordinary arrays can change size and hold mixed types, and each array is an object. That flexibility is convenient but can have performance costs. section 10.1
A type-coercion surprise
The expression `[] + {}` produces `"[object Object]"`, while `[] + ""` produces `""`. JavaScript can coerce values instead of rejecting an operation with mismatched types. You need not memorize every coercion rule, but unexpected types deserve attention: `addOne("10")`, if allowed to run as a function that adds `1`, produces `"101"` rather than `11`. section 1.3.1
TypeScript adds compile-time type checking to JavaScript development, catching some mismatches before code runs. ESLint can enforce project rules, and Prettier can settle formatting choices. These tools provide guardrails; they do not change the need to understand JavaScript’s runtime behavior. section 2.0 section 2.1
Frameworks can supply the core of a web or server application and save implementation time. For apps, an embedded web view lets JavaScript drive an HTML-and-CSS interface, while React Native renders platform-specific UI components. Choose for the target environment rather than assuming one approach fits every project. Likewise, check support for newer ECMAScript features in the runtimes you must serve; older browsers may require transpilation. section 1.2 section 1.2.3 section 1.5

















