43. Parameters and Arguments
It's important to distinguish between parameters and arguments when working with functions.
Parameters
Parameters are the variable names listed in the function definition. They act as placeholders for the values the function expects to receive.
javascript // 'p1' and 'p2' are parameters function subtract(p1, p2) { console.log(p1 - p2); }
Arguments
Arguments are the actual values passed to the function when it is called.
javascript subtract(10, 3); // 10 and 3 are the arguments // Output: 7
Handling Missing Arguments
If you call a function without providing enough arguments, the missing parameters are automatically assigned the value undefined.
javascript
function log(message, level) {
console.log([${level}]: ${message});
}
log('System startup'); // level will be undefined // Output: [undefined]: System startup