
How to Write a Function That Accepts an Options Object With Defaults
Write a JavaScript function with an options object and defaults using destructuring, nested options, validation and TypeScript types. Node.js 24.
Tag
36 posts

Write a JavaScript function with an options object and defaults using destructuring, nested options, validation and TypeScript types. Node.js 24.

ES2026 adds Array.fromAsync, Error.isError, Math.sumPrecise, Uint8Array base64, Iterator.concat, Map getOrInsert and JSON source text. See fallbacks.

Write one JavaScript function that accepts an optional callback and otherwise returns a promise, with error-first rules, no double calls and tests. Node.js 24.

A realm has its own built-in objects, so an array from an iframe or vm context fails instanceof Array. See the checks that work across realms.

A working primer on JavaScript regular expressions: syntax, flags, match and matchAll, named groups, lookarounds, replace and the global flag state trap.

Move CPU-heavy work off the Node.js event loop with node:worker_threads: start a worker, pass data and results, handle errors and build a small worker pool.

Strict mode turns silent mistakes into errors and is already on in ES modules and classes. See what it changes and when to add the directive.

Wrap any JavaScript function with logging for arguments, results, errors and duration, handle async functions, keep this, and avoid leaking secrets. Node.js 24.

Hoisting means JavaScript registers declarations before running code, so function declarations work early and var reads undefined. See what each kind does.

Run one Node.js HTTP server per CPU core with node:cluster: fork workers, share a port, restart crashed workers and know when a process manager is simpler.

Create elements dynamically with createElement, append, template and replaceChildren, set text and attributes safely, and add many nodes quickly.

Write a Node.js script that runs on Windows, macOS and Linux: build paths with path, find home and temp folders, avoid shell commands and spawn programs safely.