Search code examples
javascriptdocumentationjsdoc

JSDoc: how to specify optional return value properly


My task is to document function with right JSDoc. When function returns true it triggers something, otherwise it doesn't. But in any case the return value must be of boolean type.

My variant is:

* @return {boolean=false} trigger for default event handler:
*
* Value | Description
*-------|-------------------------------
* true  | disable default event handler
* false | enable default event handler

Help me please to choose right solution. Thanks!


Solution

  • I added simply one line below possible return values:

    * @return {boolean} trigger for default event handler:
    *
    * Value | Description
    *-------|-------------------------------
    * true  | disable default event handler
    * false | enable default event handler
    *
    * Return `false` or nothing if you want that default event handler stayed untouched.
    

    I think this is the best solution because it is clear and valid.