Last Updated: February 25, 2016
·
1.394K
· paksoy

Function arity in JavaScript

You can check the number of arguments a JavaScript function takes by using the length property.

A function that takes 0 arguments will have length of 0:

(function(){}).length === 0

And, a function that takes 3 arguments will have length of 3:

(function(a, b, c){}).length === 3

This can be useful for building callback API's that can treat callbacks differently based on arguments defined.