Home > Article > Web Front-end > Summary of usage of brackets () in javascript_Basic knowledge
1. Increase priority
(1 2)*3 Consistent with mathematical operations, first calculate 1 2 and then multiply by 3 to get 9
can also be other expressions, such as:
2. The parameters of the function should be placed in brackets ()
For example: alert(1)(function(){})(), at this time alert(1) is executed first. Since it complies with the function expression rules for immediate execution, the return value of alert(1) will be used as a function , and the value in the latter bracket is passed in as a parameter, but alert(1) returns undefined, so an error will be reported. The solution is to add ";" or "," after alert(1) to split it into two expressions.
You can also use
When executing a function alone, parentheses are also required and cannot be omitted, such as: fun(), fun(1,2,3)
4. Execute single or multiple expressions and return the value of the last expression. Multiple expressions need to be separated by commas ","
5. Conditional expression , similar to 4, but used in conditional judgment