Declarative Statements (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.
Declarative Statements (JavaScript)
API ID: CountStmtDeclJavascriptLanguages: Web
Targets: Architectures, Files, Project
Number of JavaScript declarative statements.
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>
var greetingCount = 0; (9), function greetUser(name) { ... } (11), and let message = greetUser("Ada"); (16) are the three declarations, giving CountStmtDeclJavascript = 3. Note that line 16 also counts as an executable statement, since it calls greetUser() as well as declaring message.
See Executable Statements (JavaScript) for the complementary breakdown, and Declarative Statements for the combined count across all languages.
Targets By Language:- Web: Project, File
- This metric can be disabled from "Project Configuration/Metrics/Lines and Statements" with the "Show statement count metrics" option.
- This metric can be enabled from "Project Configuration/Metrics/Lines and Statements" with the "Breakdown counts by web language" option.