Analyse code complexity

Estimate cyclomatic complexity for JavaScript or TypeScript functions from decision tokens.

freeworks offlinenothing uploaded
ToolCode Complexity Analyzer
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

The source is scanned for function declarations and indicators such as if, loops, case, catch, ternary, and logical operators. Each function starts at one, increments for matched decisions, and is assigned a triage band.

  • Starting at one follows McCabe’s metric.
  • The 1–5, 6–10, and 11+ bands are review heuristics.

Worked example

Analyze function complexity
Calculate cyclomatic complexity of JavaScript functions
Input
											function validate(x) {
  if (x > 0 && x < 100) {
    return true;
  } else if (x === 0) {
    return null;
  }
  return false;
}
										
Output
												Cyclomatic Complexity Analysis
Total: 6
Global scope: 1
Functions: 1

Per-function breakdown:
  validate (line 1): 5

Legend: 1-5 = simple, 6-10 = moderate, 11+ = complex
											

When to use this

Refactor reviews, CI trend reports, and teaching examples compare control-flow complexity.

Edge cases

  • A token inside a string can be counted if masking misses it.
  • Generated code can score high despite low maintenance risk.
  • The metric does not measure coupling, readability, or runtime cost.

References