'Arguments Object is Empty Despite Setting Default Argument Value – is there a Workaround?

Given this function (e.g. in node.js)

> function f (a = 1) { return arguments; }
undefined
> f(1)
[Arguments] { '0': 1 } // arguments object contains value for argument a
> f()                  // invoke function f without argument
[Arguments] {}         // arguments object is empty despite default value

I need to be able to obtain default values if no argument is given.

Can anybody help me with this?



Solution 1:[1]

Straight from the docs: arguments is an Array-like object accessible inside functions that contains the values of the arguments passed to that function.

This means that arguments will only hold the values that are actually passed to the function when a call is made.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Radu Diță