1

What is the right way to comment null value in javascript? For example:

/**
 * Hides an element.
 * @param {String} id - element id (can be {@code null}).
 * @returns {undefined}.
 */
function hide(id) {

    if (id !== null) {
        document.getElementById(id).style.visibility = 'hidden';
    }
}

But the tag {@code null} not working...

Ernestas Gruodis
  • 8,567
  • 14
  • 55
  • 117

2 Answers2

0

Just came across the same issue myself and found that using backticks (``) did the trick for me. Using the JSDoc comment used in your example, it should look like:

/**
 * Hides an element.
 * @param {String} id - element id (can be `null`).
 * @returns {undefined}.
 */
Jeff G
  • 122
  • 1
  • 6
0

The proper way to document this function in JSDoc is like the following snippet:

/**
 * Hides an element.
 * @param {String | null} id - element id (can be `null`).
 */
function hide(id) {
    if (id !== null) {
        document.getElementById(id).style.visibility = 'hidden';
    }
}
lepsch
  • 8,927
  • 5
  • 24
  • 44