javascript will set any missing parameters to undefined .
function fn(a) { console.log(a); } fn(1);
This works for any number of parameters.
function example(a,b,c) { console.log(a); console.log(b); console.log(c); } example(1,2,3); //outputs 1 then 2 then 3 to the console example(1,2); //outputs 1 then 2 then undefined to the console example(1); //outputs 1 then undefined then undefined to the console example(); //outputs undefined then undefined then undefined to the console
also note that the arguments array will contain all the arguments provided, even if you supply more than is required by the function definition.
barkmadley Dec 04 '09 at 12:35 2009-12-04 12:35
source share