From 07c7c3349d20319146023c159a5a8e2d6cfea2ba Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Wed, 22 Apr 2026 18:00:34 +0900 Subject: [PATCH] doc: use mjs/cjs blocks for callbackify null reason example --- doc/api/util.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/api/util.md b/doc/api/util.md index b9e21d8da8022f..8912247e33d5ec 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -76,7 +76,24 @@ wrapped function rejects a `Promise` with a falsy value as a reason, the value is wrapped in an `Error` with the original value stored in a field named `reason`. -```js +```mjs +import util from 'node:util'; + +function fn() { + return Promise.reject(null); +} +const callbackFunction = util.callbackify(fn); + +callbackFunction((err, ret) => { + // When the Promise was rejected with `null` it is wrapped with an Error and + // the original value is stored in `reason`. + err && Object.hasOwn(err, 'reason') && err.reason === null; // true +}); +``` + +```cjs +const util = require('node:util'); + function fn() { return Promise.reject(null); }