JavaScript as the web runtime language
ECMAScript powers browsers and Node.js: functions close over lexical scope, objects group state and behavior, and the event loop schedules callbacks, promises, and async/await continuations. Modules (import/export) isolate units; bundlers emit compact IIFEs or ESM for deployment.
Beautifying reveals block structure for review of bundle snippets, stack-trace copies, or console exports. Minification removes comments and whitespace via a parser—without the mangling and tree-shaking passes your production bundler applies. TypeScript and JSX are separate grammars until compiled to JavaScript.
JavaScript language — background
Core syntax: statements, functions, and blocks
- Statements end with semicolon or ASI rules; blocks use { } for grouping and scope.
- Functions declare with function, arrow (=>), or method shorthand; return passes values to callers.
- const and let are block-scoped bindings; var is function-scoped and hoisted with undefined initialization.
- Control flow uses if/else, switch, for/while, try/catch/finally, and labeled break/continue.
Primitives, object references, and equality
- Primitives: undefined, null, boolean, number, bigint, string, symbol—compared by value where applicable.
- Objects and arrays are references; shallow copy shares nested references unless cloned deeply.
- === avoids coercion; Object.is treats NaN as equal to NaN unlike ===.
- Optional chaining (?.) and nullish coalescing (??) shorten guards on nullable references.
ES modules and asynchronous execution
- ES modules use static import/export; bundlers resolve dependencies into graphs.
- Promises represent eventual values; async functions return promises and pause with await.
- Microtasks (promise callbacks) run before the next macrotask (setTimeout, I/O)—order matters in tests.
- Top-level await is module-scoped; classic scripts cannot use it without bundler wrapping.
Event loop, tasks, and the call stack
- Synchronous code runs to completion on the call stack; each function invocation pushes a new frame.
- Macrotasks (setTimeout, I/O callbacks) queue after the stack clears; one macrotask runs per turn by default.
- Microtasks (promise reactions, queueMicrotask) drain completely after the current script and before the next macrotask.
- async/await desugars to promise chains—await yields microtasks, not a new thread.
Where readable JavaScript helps
Bundle and DevTools forensics
One-line vendor chunks hide control flow—indentation exposes conditionals during incident review before you attach a debugger.
Teaching and interview snippets
Algorithm or API examples copied from docs become diff-friendly when braces and callbacks line up—still validate logic separately from layout.