1. Higher priority
(1 + 2) * 3 is consistent with that in mathematical operations. Calculate 1 + 2 and multiply by 3 to get 9.
It can also be other expressions, such:
Copy codeThe Code is as follows: (a + (function (I) {return I} (2) * c
2. The function parameters should be placed in brackets ()
Copy codeThe Code is as follows: function fun (a, B, c)
{
//...
}
3. Execute the function expression immediately.
Copy codeThe Code is as follows:
(Function fun (a, B, c)
{
//...
}) (1, 2, 3)
The parameters in parentheses (, 3) correspond to the parameters of the previous function. When the code in the first bracket complies with the expression rules, the previous Code will be executed as a function expression, therefore, it is best to add ";" in front of the first function expression to separate them. Otherwise, the value of the previous expression is not a function error.
For example: alert (1) (function () {}) (), alert (1) is executed first. Because it complies with the function expression rules for immediate execution, alert (1) the return value is used as a function, and the value in the last bracket is passed as a parameter, but alert (1) returns undefined, so an error is returned. The solution is to add ";" or "," After alert (1) and split it into two expressions.
Immediate execution can also be used
Copy codeThe Code is as follows:
(Function fun (a, B, c)
{
//...
} (1, 2, 3 ))
! Function fun (a, B, c)
{
//...
} (1, 2, 3)
Void function fun (a, B, c)
{
//...
} (1, 2, 3)
As long as the function conforms to the syntax rules of the function expression.
When executing a function separately, brackets must also be added and cannot be omitted, for example, fun (), fun (, 3)
4. Execute one or more expressionsAnd returns the value of the last expression. Multiple Expressions must be separated by commas (,).
Copy codeThe Code is as follows: (1, 2 + 3, 4 + 5, 6) // The Code will be executed once, and 6 will be used as the return value.
5. conditional expressions, Similar to 4, but used for condition judgment
Copy codeThe Code is as follows: if (a + B = c) {}// the content between if and {needs to be placed in parentheses