Programming concepts

Explicit result object

Try the free JavaScript compiler

An application convention for ordinary success or expected failure data, not an ECMAScript special type. Branch on the discriminator, not value truthiness.

Formal Syntax & Structure

javascript syntaxjavascript
{ok: true, value: result} or {ok: false, error: reason}

Working Example

Example Snippetjavascript
const r={ok:true,value:0}; console.log(r.ok,r.value);
JavaScript Reference