A JavaScript function
does not perform any checking on parameter values (arguments).
Function Parameters and Arguments
Earlier in this tutorial, you learned that functions can have parameters:
// code to be executed
}
Function parameters are the names listed in the function definition.
Function arguments are the real values passed to (and received by) the function.
Parameter Rules
JavaScript function definitions do not specify data types for parameters.
JavaScript functions do not perform type checking on the passed arguments.
JavaScript functions do not check the number of arguments received.
Default Parameters
If a function is called with missing arguments (less than declared), the missing values are set to undefined
.
Sometimes this is acceptable, but sometimes it is better to assign a default value to the parameter:
Example
if (y === undefined) {
y = 2;
}
}
ECMAScript 2015 allows default parameter values in the function declaration:
// function code
}
Practice Excercise Practice now