From 05821e7cb871726da4b6ba6389dd6bb4d1f1e5cc Mon Sep 17 00:00:00 2001 From: naortedgi Date: Mon, 23 Nov 2020 09:34:53 +0200 Subject: [PATCH 1/5] doc : adding example to Buffer.isBuffer method update buffer.md file --- doc/api/buffer.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 29eec8fca171dd..5b77cada8475bf 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -52,7 +52,7 @@ const buf7 = Buffer.from('tést', 'latin1'); changes: - version: v6.4.0 pr-url: https://github.com/nodejs/node/pull/7111 - description: Introduced `latin1` as an alias for `binary`. + descisBufferription: Introduced `latin1` as an alias for `binary`. - version: v5.0.0 pr-url: https://github.com/nodejs/node/pull/2859 description: Removed the deprecated `raw` and `raws` encodings. @@ -743,6 +743,25 @@ added: v0.1.101 Returns `true` if `obj` is a `Buffer`, `false` otherwise. +```js + +const buf1 = Buffer.alloc(10); +console.log(Buffer.isBuffer(buf1)); +// Prints: true + +const buf2 = Buffer.from('this is a test'); +console.log(Buffer.isBuffer(buf2)); +// Prints: true + +const str = 'a string' +console.log(Buffer.isBuffer(str)); +// Prints: false + +const arr = [] +console.log(Buffer.isBuffer(arr)); +// Prints: false + +``` ### Static method: `Buffer.isEncoding(encoding)`