JavaScript parentheses, brackets, curly braces Learning Summary

Source: Internet
Author: User

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

  1. function () {} () //anonymous function immediate execution, parsing period error
  2. {}.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.
  3. Details can be found in http://blog.csdn.net/woshinia/article/details/18666223

JavaScript parentheses, brackets, curly braces Learning Summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.