The basic concept and use of functions in Js

Function:
Define function:
1. Declarative function
Syntax ==> function function name () {}
function is the keyword for declaring the function
Space---separate keywords and function name Function
name---It is recommended to follow the variable naming rules and naming Specification
()---parameter
{}---storage code segment'
2. Assignment function
var function name=function(){};

Call function: function name()

The difference between the two methods:
the two declaration methods, the calling method is the same, but the timing of the call is different
Declarative function ---- can be called before the declaration, or the
assignment function can be called after the declaration - only It can be called after the declaration, and an error will be reported before the declaration

Function parameters:
In JS, function parameters are divided into two types--formal parameters--actual parameters

1\Formal parameter:
written in () in the function definition phase,
similar to a variable that can be used inside the function,
the name follows variable naming rules and specifications, and
the value is determined by the function actual parameter
2\Actual parameter is written
in () in the function call phase
Is an accurate value, mainly to assign values ​​to the formal parameters of the function

PS: Multiple formal parameters and actual parameters can be written. When there are multiple, "," is used to separate them. When there are multiple, they correspond one-to-one from
left to right.

The relationship between the number of function parameters:
the same number - one-to-one correspondence from left to right
More actual parameters - one-to-one correspondence in the order above, the extra actual parameters are not received by formal parameters, and
formal parameters cannot be used directly - --The front corresponds to one by one in order, because the extra actual parameters have no
actual parameter assignment, so Undefined will be displayed when used

arguments----indicates the set (pseudo-array) attribute of all actual parameters
:
1\length---
indicates the length, how many data are in arguments, that is, how many actual parameters your function call has,
it is a read-write attribute
2\ The arrangement of arguments
is arranged according to the serial number, the serial number starts from 0, and then +1----index/subscript
3\arguments The operation of a certain data in arguments
can rely on the index to operate a certain data in arguments
---arguments[index ]===>Indicates the data of the index position to be obtained
==>arguments[index]=The value to be set
===>Indicates to change the data of the corresponding index position in arguments
PS==>
If the corresponding index is arguments An index that is not in it, then it is added
If there is, it is modified
 

Guess you like

Origin blog.csdn.net/weixin_69419680/article/details/124226817