JavaScript function nuances
looking at the details of a JavaScript function
Function's built-in properties
Every function (also an object) has two properties:
length
refers to the amount of argumentse.g.
function myFunction(x,y,z)
has alength
of 3
prototype
refers to all the properties and methods that the object can use
Functions that return multiple values
We can return
more than one object from a function:
In ES6, we can use destructuring as such, to make using this array easier:
Functions that do recursion
Recursive functions can call themselves:
We can easily see that this would result in an endless loop - like a dog chasing its tail!
Exit conditions of a recursive function
So, to work like a (sane) normal function, a recursive function must have an exit condition:
The exit condition in the above is the silent else
branch which lets the function not call itself again :)
Last updated