The most correct value for the error parameter is "undefined", but most of
us are lazy and type "null" instead.  In most code it expects the err
parameter to be either falsy or an Error instance, so it doesn't matter if
you use false, undefined, null, 0, or even "".

While there are some functions that never emit an error, if there is any
chance they would emit one in the future, save yourself the trouble and
reserve the err parameter.  Also it makes the function work with
flow-control tools and wrappers that assume the pattern.

On Wed, May 30, 2012 at 4:05 AM, Mariusz Nowak <[email protected]> wrote:

> It should be null or undefined only, everything else is a value, and can
> mistakenly accepted as an error.
>
> There are however asynchronous functions that never resolve with an error
> (e.g. path.exists) and as there's no point in always sending null to their
> callbacks, they're designed to pass success value as first argument (in
> case of path.exists true or false).
>
> --
> Mariusz Nowak - @medikoo
>
>
> On Wednesday, May 30, 2012 3:24:06 AM UTC+2, Daniel R. wrote:
>>
>> Is there consensus on the value to pass to a callback if there isn't
>> an error and there may or may not be a resulting value. A quick survey
>> of node.js code along with popular modules seems to indicate that null
>> is most common but undefined and false also pop up frequently. While
>> any falsey value works I was curious if one was preferred.
>>
>> -- Daniel R. <[email protected]> [http://danielr.neophi.com/]
>>
>  --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to