Home  >  Article  >  Web Front-end  >  JavaScript Enhancement Tutorial - Function Parameters

JavaScript Enhancement Tutorial - Function Parameters

巴扎黑
巴扎黑Original
2016-12-05 11:34:571077browse

This article is the official HTML5 training tutorial of H5EDU organization. It mainly introduces: JavaScript enhancement tutorial - function parameters

JavaScript function parameters
JavaScript functions do not perform any checks on the values ​​of parameters (arguments).
Function explicit parameters and hidden parameters (arguments)
In the previous tutorial, we have learned about the explicit parameters of the function:
functionName(parameter1, parameter2, parameter3) {
code to be executed
}
Explicit function parameters Listed when the function is defined.
Function hidden parameters (arguments) are the real values ​​passed to the function when the function is called.
Parameter Rules
The parameters do not specify data types when defining JavaScript functions.
JavaScript function does not detect hidden parameters (arguments).
The JavaScript function does not detect the number of hidden parameters (arguments).
Default parameters
If a function is called without parameters, the parameters will be set to: undefined by default
Sometimes this is acceptable, but it is recommended to set a default value for the parameter:
Example

function myFunction(x, y) { 
    if (y === undefined) { 
          y = 0; 
    } 
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn