Parameters & Arguments
Understanding function inputs.
Examples
Default Parameters
Using default values for parameters.
function myFunction(x, y = 10) {
return x + y;
}
console.log(myFunction(5)); // 15
console.log(myFunction(5, 2)); // 7Arguments Object
Accessing function arguments using the arguments object.
function findMax() {
let max = -Infinity;
for (let i = 0; i < arguments.length; i++) {
if (arguments[i] > max) {
max = arguments[i];
}
}
return max;
}
console.log(findMax(4, 5, 6, 1)); // 6Test Your Knowledge
JavaScript Quiz
No quiz available for this topic yet.