How do I measure code complexity online?
Paste your JavaScript or TypeScript code and click Analyze to see cyclomatic complexity, cognitive complexity, nesting depth, and maintainability index for every function. Each function gets a risk rating with actionable refactoring recommendations. All analysis runs in your browser — your code never leaves your device.
function add(a: number, b: number) {
return a + b;
}Function: add Cyclomatic: 1 (low) Cognitive: 0 (low) Nesting: 0 Maintainability: A Overall Grade: A No issues found
Code Complexity Analyzer
Paste JavaScript or TypeScript code to analyze cyclomatic complexity, cognitive complexity, nesting depth, and maintainability index per function. 100% client-side — your code never leaves your browser.
Tips & Best Practices
Aim for cyclomatic complexity under 10 per function
Functions with complexity above 10 are hard to test and maintain. Each branch (if/else, switch case, ternary, catch) adds a test case you need to write. A function with complexity 15 needs at minimum 15 test paths. Extract helper functions or use early returns to reduce branching.
Low complexity doesn't mean good code — it means testable code
A function that calls 20 external services sequentially has low cyclomatic complexity (no branches) but is a maintenance nightmare. Complexity metrics measure one dimension of code quality. Combine with nesting depth, cognitive complexity, and function length for a complete picture.
Use complexity to prioritize refactoring in legacy codebases
Sort functions by complexity to find the highest-risk code. Functions with complexity 25+ are the ones that cause the most bugs and take the longest to modify. Refactor these first — the ROI on reducing a function from complexity 30 to three functions of complexity 8 is enormous.
High complexity correlates with more vulnerabilities
Research shows that functions with cyclomatic complexity above 15 are 2-3x more likely to contain security bugs. Complex branching logic hides edge cases where input validation is skipped or authorization checks are bypassed. High complexity code deserves extra security review.
Frequently Asked Questions
What is cyclomatic complexity and why does it matter?
What is cognitive complexity and how is it different from cyclomatic?
What is the maintainability index and how is the grade calculated?
Is this tool accurate enough for production use?
Related Inspect Tools
XPath Tester
Test XPath expressions against XML data with real-time evaluation — select elements, filter by attributes, navigate axes, and use XPath functions
SQL Playground
Run SQL queries in your browser with a full SQLite database powered by WebAssembly — practice JOINs, CTEs, window functions, aggregations, and more
JWT Decoder
Decode and inspect JSON Web Tokens instantly
Regex Tester
Test regular expressions with real-time match highlighting