Nothing will happen- meaning you won't get an error or a warning as passing the parameters in javascript is optional.
All the parameters that weren't "supplied" will have the undefined
value.
function foo(x, y, z){
//...
}
foo(1);
Inside the foo
function now:
function foo(x, y, z){
x === 1
y === undefined
z === undefined
}
You can even pass more arguments, like:
foo(1,2,3,4,5,7); // Valid!
You can know the amounts of parameters supplied by arguments.length
from inside the function.
function foo(x, y, z) {
console.log('x value: ' + x);
console.log('y value: ' + y);
console.log('z value: ' + z);
console.log('Arguments length: ' + arguments.length);
}
console.log('Zero parameters');
foo();
console.log('Four parameters');
foo(1, 2, 3, 4);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…