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.
Written by Mustafa Paksoy
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Related Tags
#javascript
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#