You need be careful with the length property of a function. It actually returns the number of parameters (not arguments - those are what we pass in) a function accepts, but only the number up to the first parameter that doesn't have a default value assigned:
Yes, you are correct. In my case, all I needed was a way to get number of parameters a function is accepting to solve a specific LeetCode problem. But yes, one should be careful while using length property on functions due to the reasons you've explained with examples.
Thanks!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You need be careful with the
lengthproperty of a function. It actually returns the number of parameters (not arguments - those are what we pass in) a function accepts, but only the number up to the first parameter that doesn't have a default value assigned:Yes, you are correct. In my case, all I needed was a way to get number of parameters a function is accepting to solve a specific LeetCode problem. But yes, one should be careful while using
lengthproperty onfunctionsdue to the reasons you've explained with examples.Thanks!