scitools.com

← Metric catalog

Comment Lines (JavaScript) is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.

Comment Lines (JavaScript)

API ID: CountLineCommentJavascript
Languages: Web
Targets: Architectures, Files, Project

Number of JavaScript lines containing a comment.

For example:


<!DOCTYPE html>
<html>
<head>
  <title>Welcome</title>

  <!-- Greeting script: tracks visits and confirms with the user -->
  <script>
    // Number of times the page has greeted someone
    var greetingCount = 0;

    function greetUser(name) {
      greetingCount++;
      return "Hello, " + name + "!";
    }

    let message = greetUser("Ada");
    console.log(message);

    if (greetingCount > 0) {
      confirm(message);
    }
  </script>
</head>
<body>
  <h1>Welcome to the site</h1>
  <p>Have a look around.</p>
</body>
</html>

The // Number of times the page has greeted someone comment (line 8) is the only JavaScript comment, giving CountLineCommentJavascript = 1.

See Comment Lines (HTML) for comments outside embedded scripts, and Comment Lines for the language-independent metric this breaks down.

Targets By Language: Configuration: