Code Commenting

Code commenting

Here are some simple rules that must be followed while writing comments on your codebase.For more detailed information, these links can be followed :

  • JSDoc (opens in a new tab)

  • Coding standards (opens in a new tab)

    Inline comments inside methods and functions should be formatted as follows:

    Single line comments

    They should begin with doule forward slashes

    // Extract the array values.

    Multi-line comments

    /*
     * This is a comment that is long enough to warrant being stretched over
     * the span of multiple lines. You'll notice this follows basically
     * the same format as the JSDoc wrapping and comment block style.
     */

    Important note: Multi-line comments must not begin with /*_ (double asterisk). Use /_ (single asterisk) instead.

    Documentation comment

    These types of comments are signified by using double asterisk after single forward slash i.e /** .The double asterisk is used to indicate that the comment contains special information, such as the types of parameters and return values of a function.

    /**
     * This is documentation comment
     *
     * This function takes in two parameters, a number and a callback function
     * The function will square the number, and then pass the result to the callback
     *
     * @param {number} num - The number to be squared
     * @param {function} callback - The function to be called with the squared result
     * @returns {number} - The result of the square operation
     */
    function squareAndCall(num, callback) {
      const squaredNum = num * num;
      callback(squaredNum);
     
      return squaredNum;
    }

    Aligning comments

    Related comments should be spaced so that they align to make them more easily readable.

    /**
     * @param {very_long_type} name           Description.
     * @param {type}           very_long_name Description.
     */