As a programmer, dealing with parentheses is essential. Do you know that in different contexts, the function of parentheses is not the same, today let us briefly summarize the use of JavaScript parentheses, brackets, curly braces.
In general, there are five semantics for JavaScript parentheses, four semantics for brackets, and four semantics for curly braces.
Parentheses:
Semantics 1, function declaration when parameter table (formal parameter)
Semantics 2, combined with some statements to achieve certain qualifiers (if, for, etc.)
Semantics 3, used with new to pass values (arguments)
Semantics 4, as a call operator for a function or an object method (if a parameter is defined, it can be passed as an argument with semantic 3)
Semantics 5, forced expression operations (often with Eval parsing json and anonymous functions self-executing)
Middle brackets:
Semantics 1, declaring an array
Semantics 2, taking array members
Semantics 3, defining object members (you can define identifiers at the beginning of a number without following the rules for identifiers)
Semantics 4, taking object members
Curly braces:
Semantic 1, the organization of compound statements, which is the most common
Semantics 2, Object Direct Volume Declaration (Assignment object)
Semantics 3, declaring a function or function direct value assignment
Semantic 4, Syntax notation for structured exception handling (Try...catch statement)
PS: (For parentheses semantics 5, force expression arithmetic
- function () {} () //anonymous function immediate execution, parsing period error
- {}.constructor //Get the constructor of object's direct amount, parse period error is actually JS's "statement first" in mischief, that is {} is understood as a compound statement block instead of the semantics of the direct amount of the object or the direct amount of the function. You can use the well-known method of adding a mandatory operator () to a value.
- Details can be found in http://blog.csdn.net/woshinia/article/details/18666223
JavaScript parentheses, brackets, curly braces Learning Summary