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
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#