Optional Arguments In Javascript
Why doesn't this function throw an error if the remaining arguments are missing? showStatistics('Mark Teixeira', 'New York Yankees', '1st Base'); Here is a the function defined: f
Solution 1:
Any argument that is not passed appears as undefined
inside the function. In JavaScript there is no method overloading.
Solution 2:
Remember that "arrays" in JS area actually associative. So the 2, 3, ... that you put in as indexed area really just hash keys. You could also check the value of arguments[54876]. That would not fail, but return to you undefined. So even though you're thinking of your parameter array as having only three valid indices and anything else giving you something along the lines of "index out of bounds", you really have three valid entries and lookup with any other keys don't fail, but give you undefined.
Post a Comment for "Optional Arguments In Javascript"