iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
The exact way to inspect a function depends on its language—and on whether you mean its declared parameters or the arguments supplied in a particular call. In Python, inspect.signature() can show supported callables’ parameters and metadata. In JavaScript, fn.length reports only a restricted formal-parameter count, not parameter types or the number passed in a specific call. In TypeScript, inspect the function’s type and any overload signatures. The examples below cover all three; name your language and version if you need an exact method for another one.
Parameters and arguments are not the same thing
A function’s parameters are the slots described by its signature. Arguments are the values supplied when the function is called. For example, in greet(name, greeting = "Hello"), name and greeting are parameters; in greet("Mina"), "Mina" is the one argument supplied by that call.
A signature can tell you more than a count. It may include parameter names and kinds, optional type annotations, default values, and a return type. The typing specification defines a function signature as its parameters—including their names, kinds, optional declared types, and default status—plus its return type. Python callable typing specification
Decide what you need to know before inspecting a function:
#1 Best Overall
- Accepted call shape: inspect the signature or type declaration.
- Values passed in one call: examine that call site, or use a language feature that reports the current invocation’s argument count.
- Expected types: look for annotations or static declarations; runtime introspection may not expose them.
Python: inspect a supported callable’s signature
Python’s standard-library inspect.signature() returns a Signature for supported callables. Each parameter has a name, kind, annotation, and default value. An annotation may be absent, so do not infer a type when one is not declared.
from inspect import signature
sig = signature(fn)
print(sig)
for name, param in sig.parameters.items():
print(name, param.kind, param.annotation, param.default)
For example, a printed parameter kind distinguishes positional-only, positional-or-keyword, and keyword-only parameters. Python also supports variadic positional parameters (*args) and variadic keyword parameters (**kwargs). Those can accept zero or more additional values, so counting named parameter slots does not necessarily tell you the maximum number of arguments a call can supply. Python 3.12 inspect documentation · Python callable typing specification
When Python cannot provide a signature
Not every callable exposes introspection metadata. Some built-ins implemented in C, for example, may not provide enough information. Depending on the object and implementation, signature(fn) can raise ValueError when a signature cannot be provided or TypeError for an unsupported object. In that case, check the callable’s official documentation or source rather than guessing its parameters or types. Python 3.12 inspect documentation
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteJavaScript: distinguish formal count from call count
fn.length reports a limited count of formal parameters; it is not a general description of every call the function accepts. The rules are easy to miss: parameters after the first default-valued parameter do not count, a destructuring pattern counts as one parameter, and a rest parameter is excluded. MDN: Function.length
Rank #3
function example(a, b = 1, ...rest) {}
console.log(example.length); // 1
Here, example.length is 1; it does not mean the function can accept only one value. Rest parameters can collect additional arguments. To find how many values were passed to a particular invocation, read arguments.length inside the function body. That is a call-specific count, not a declaration of the function’s full accepted call shapes. MDN: Function.length
Ordinary JavaScript function syntax does not declare parameter types, and neither fn.length nor arguments.length reveals what types callers are expected to pass. Consult the function’s documentation or source; if the library provides TypeScript declarations, those can describe its static call contract.
Rank #4
TypeScript: read the function type and overloads
A TypeScript function type expression states parameter and return types, as in (a: string) => void. A function can also have optional parameters, marked with ?, and required parameters are checked at typed call sites. These declarations describe TypeScript’s static contract; they do not make JavaScript enforce the types at runtime. TypeScript Handbook: Functions
Some functions expose several permitted call shapes through overload signatures. For instance, one overload might accept a timestamp while another accepts month, day, and year. Callers see the overload signatures—not necessarily the implementation signature—so inspect the declarations that are visible to callers rather than counting parameters in the function body alone. TypeScript Handbook: More on Functions
Quick Recap
Best Value
Choose the inspection method for your question
| What you want to know | Useful place to look | Important qualification |
|---|---|---|
| Declared parameters and metadata in Python | inspect.signature(fn) |
Works for supported callables; annotations may be absent, and some callables cannot be introspected. Python 3.12 inspect documentation |
| Restricted formal-parameter count in JavaScript | fn.length |
Defaults, rest parameters, and destructuring affect the count; it does not give types or a specific call’s argument count. MDN: Function.length |
| Values passed to a JavaScript invocation | arguments.length inside the function |
Reports that invocation’s argument count, not parameter types or the function’s full call contract. MDN: Function.length |
| Static types and permitted call forms in TypeScript | Function type, call signature, and overload declarations | Overloads describe public call shapes; static types are not runtime enforcement. TypeScript Handbook: More on Functions · TypeScript Handbook: Functions |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

