The exact method depends on the language—and on whether you mean a function’s declared parameters or the arguments supplied in one call. A signature describes the parameters a function accepts; a call supplies values for them. Defaults and variadic parameters mean those counts do not always match. In Python, start with inspect.signature(fn); in JavaScript, fn.length gives only a limited count of formal parameters; in TypeScript, inspect the function type and any overload declarations.
First distinguish parameters from arguments
Parameters are the named slots in a function’s signature. Arguments are the values provided when calling it. For example, in add(a, b), a and b are parameters; in add(2, 3), 2 and 3 are arguments.
As an Amazon Associate I earn from qualifying purchases.
To find what a function accepts, inspect its signature or type declaration. To count what was supplied in a particular call, examine that call or use a language-specific mechanism available inside the function. Optional or defaulted parameters can be omitted, while variadic parameters can accept additional values, so a signature’s parameter count does not necessarily give a single fixed number of accepted arguments.
What a function signature can tell you
A signature may describe more than a count: parameter names, whether parameters are positional or keyword-only, optional type annotations, default values, and the return type. The Python typing specification defines a function signature as its parameters—including their names, kinds, optional declared types, and default status—plus its return type. Read the callable typing specification.
Keep the limits of that information in mind. A parameter with no annotation has no declared type to inspect; its missing annotation does not establish what type callers should pass. And some languages keep type information in static declarations rather than exposing it through runtime function objects.
Python: inspect a callable’s signature
Python’s standard-library inspect.signature() returns a Signature object for supported callables. It exposes parameters and their kinds, annotations, and defaults:
Rank #2
from inspect import signature
sig = signature(fn)
print(sig)
for name, param in sig.parameters.items():
print(name, param.kind, param.annotation, param.default)
Parameter kinds include positional-only, positional-or-keyword, keyword-only, variadic positional (*args), and variadic keyword (**kwargs). The first three describe named parameter slots; *args can collect additional positional arguments and **kwargs additional keyword arguments. Either variadic parameter can receive zero or more values. The signature API and its parameter metadata are documented in the Python 3.12 inspect documentation.
Recommended Free Tools
Check param.annotation rather than assuming every parameter has a type annotation. If it is empty, the signature does not declare a type for that parameter.
Rank #3
When Python cannot provide a signature
Not every callable exposes introspectable metadata. In CPython, some C-defined built-ins do not provide argument metadata; inspect.signature() may raise ValueError when it cannot provide a signature or TypeError for an unsupported object. In that case, consult the callable’s official documentation or source instead of inferring its parameters or types.
JavaScript: treat Function.length as a limited count
JavaScript’s fn.length reports a restricted count of formal parameters, not the number of arguments passed in a particular call and not a list of parameter types. For this function, the count is one:
function example(a, b = 1, ...rest) {}
console.log(example.length); // 1
The count includes only parameters before the first default-valued parameter. A destructuring pattern counts as one parameter, and a rest parameter is excluded. The rules are described in MDN’s Function: length reference.
Free tools Windows power users keep installed
One-click scans. No signup required.
Inside a function, arguments.length reports how many arguments were passed to that invocation. That is a different question from fn.length, which concerns formal parameters. Ordinary JavaScript function syntax does not declare parameter types, so neither count tells you what types callers are expected to provide. For that, consult the function’s documentation or source, or TypeScript declarations if the library supplies them.
Best Value
TypeScript: read the callable type and overloads
A TypeScript function type can state parameter and return types, as in (a: string) => void. Required parameters are checked at call sites; a parameter marked with ? is optional. These declarations describe TypeScript’s static contract, not runtime type enforcement by JavaScript. See the TypeScript Handbook: Functions.
A callable type may also have overload signatures that allow different call forms. For example, a function can expose one overload for a timestamp and another for separate month, day, and year arguments. Callers see the overload signatures, which need not match the implementation signature; the implementation signature itself is not visible to callers. To determine valid calls, inspect the exported function type and its overloads rather than relying on the implementation body. The Handbook explains these signatures in More on Functions.
Quick Recap
Choose the right method for your question
- Need the declared parameters? Inspect the language’s signature or type declaration.
- Need the arguments in one call? Count the values at that call site, or use a mechanism that reports the current invocation’s arguments.
- Are defaults or optional parameters present? A caller may omit them, so the number supplied can be lower than the number of declared parameter slots.
- Are parameters variadic?
*args,**kwargs, or JavaScript rest parameters can make the number of accepted values variable. - Do you need types? Look for annotations or static declarations. Runtime counts alone do not reveal types, and missing annotations are not evidence of a particular type.
- Is the function overloaded, wrapped, or native? The public call forms or available metadata may differ from the implementation or may not be introspectable.
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.




