JavaScript
Overview
JavaScript is a lightweight, interpreted (or just-in-time compiled) programming language with first-class functions. Best known as the scripting language of web pages, it also runs in many non-browser environments such as Node.js. It is a prototype-based, garbage-collected, dynamic, multi-paradigm language standardized as ECMAScript. Read this for core language semantics, asynchronous patterns, and modern module syntax.
Official sources
Core concepts
- Dynamic typing: variables are not bound to a type; values carry types and can change. Primitives include string, number, bigint, boolean, undefined, null, symbol; everything else is an object.
- First-class functions and closures: functions are values that can be passed, returned, and capture their lexical scope.
- Prototype-based inheritance: objects inherit directly from other objects via the prototype chain;
class syntax is sugar over prototypes.
- The event loop and asynchronous model: single-threaded with non-blocking I/O via callbacks, Promises, and
async/await.
- Scoping and hoisting:
let/const are block-scoped (with a temporal dead zone); var is function-scoped; declarations are hoisted.
- Strict equality vs. coercion:
=== compares without type coercion; == performs coercion and is a frequent source of surprises.
- ES modules:
import/export provide the standardized module system across browsers and Node.js.
Best practices
- Prefer
const by default and let when reassignment is needed; avoid var to escape function-scope and hoisting surprises (per MDN guidance).
- Use strict equality (
=== / !==) rather than loose equality to avoid implicit coercion bugs.
- Handle Promise rejections —
await inside try/catch, or attach .catch() — to avoid unhandled rejections.
- Use ES module
import/export for clear, statically analyzable dependencies.
Common pitfalls
- Relying on
this binding inside detached callbacks → use arrow functions (which capture lexical this) or bind explicitly.
- Loose equality and truthiness surprises (
0, "", null, undefined, NaN) → use === and explicit checks.
- Floating-point arithmetic precision (e.g.
0.1 + 0.2 !== 0.3) → round for display or use integer/bigint math where exactness matters.
- Mutating shared objects/arrays unexpectedly → copy (spread, structuredClone) before mutating when isolation is needed.
Examples
async function fetchUser(id) {
try {
const res = await fetch(`/api/users/${id}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return await res.json();
} catch (err) {
console.error("fetchUser failed", err);
throw err;
}
}
Further reading
Related skills
- ../typescript — typed superset that compiles to JavaScript
1---2name: javascript3description: Dynamic, prototype-based language of the web (ECMAScript); consult for core semantics, async, and modern syntax.4domain: language5category: language6tags: [javascript, ecmascript, web, async, es modules]7official_sources:8 - https://developer.mozilla.org/en-US/docs/Web/JavaScript9 - https://github.com/tc39/ecma26210verified: 2026-06-1611metadata:12 source: https://skillmd.com/skills/gabriel7silva/javascript13---1415# JavaScript1617## Overview18JavaScript is a lightweight, interpreted (or just-in-time compiled) programming language with first-class functions. Best known as the scripting language of web pages, it also runs in many non-browser environments such as Node.js. It is a prototype-based, garbage-collected, dynamic, multi-paradigm language standardized as ECMAScript. Read this for core language semantics, asynchronous patterns, and modern module syntax.1920## Official sources21- Docs (reference): https://developer.mozilla.org/en-US/docs/Web/JavaScript22- Language standard repo (ECMA-262 / TC39): https://github.com/tc39/ecma2622324## Core concepts25- Dynamic typing: variables are not bound to a type; values carry types and can change. Primitives include string, number, bigint, boolean, undefined, null, symbol; everything else is an object.26- First-class functions and closures: functions are values that can be passed, returned, and capture their lexical scope.27- Prototype-based inheritance: objects inherit directly from other objects via the prototype chain; `class` syntax is sugar over prototypes.28- The event loop and asynchronous model: single-threaded with non-blocking I/O via callbacks, Promises, and `async`/`await`.29- Scoping and hoisting: `let`/`const` are block-scoped (with a temporal dead zone); `var` is function-scoped; declarations are hoisted.30- Strict equality vs. coercion: `===` compares without type coercion; `==` performs coercion and is a frequent source of surprises.31- ES modules: `import`/`export` provide the standardized module system across browsers and Node.js.3233## Best practices34- Prefer `const` by default and `let` when reassignment is needed; avoid `var` to escape function-scope and hoisting surprises (per MDN guidance).35- Use strict equality (`===` / `!==`) rather than loose equality to avoid implicit coercion bugs.36- Handle Promise rejections — `await` inside `try/catch`, or attach `.catch()` — to avoid unhandled rejections.37- Use ES module `import`/`export` for clear, statically analyzable dependencies.3839## Common pitfalls40- Relying on `this` binding inside detached callbacks → use arrow functions (which capture lexical `this`) or bind explicitly.41- Loose equality and truthiness surprises (`0`, `""`, `null`, `undefined`, `NaN`) → use `===` and explicit checks.42- Floating-point arithmetic precision (e.g. `0.1 + 0.2 !== 0.3`) → round for display or use integer/bigint math where exactness matters.43- Mutating shared objects/arrays unexpectedly → copy (spread, structuredClone) before mutating when isolation is needed.4445## Examples46```javascript47async function fetchUser(id) {48 try {49 const res = await fetch(`/api/users/${id}`);50 if (!res.ok) throw new Error(`HTTP ${res.status}`);51 return await res.json();52 } catch (err) {53 console.error("fetchUser failed", err);54 throw err;55 }56}57```5859## Further reading60- MDN JavaScript Guide: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide61- ECMAScript draft spec: https://tc39.es/ecma262/6263## Related skills64- ../typescript — typed superset that compiles to JavaScript