Last Updated: February 25, 2016
·
1.572K
· 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.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
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