Use of (), {}, [] in Javascript

Source: Internet
Author: User

(), Used in the expression to change the priority of the expression. For example:
(A + B) * C;
VaR F = function (){}
VaR F = (function (){})
Return (function () {}) // defines the anonymous function and returns
(Function () {}) () // defines an anonymous function and calls

{}, Used to define methods, define method blocks, and define objects directly. For example:
{// Define the method block. I variables can be accessed outside the method block.
VaR I = 1;
Alert (I + 1 );
Alert (I + 2 );
Alert (I + 3 );
Alert (I + 4 );
}
Alert (I + 5 );

VaR A = {PA: "1", Pb: "2"}; // define the object directly. The class of this object is anonymous, so the class-related attributes cannot be used, such as prototype.

[], Defining arrays. For example
VaR buffar = [
'<Div id = "',
'', // Index 1, div ID attribute
'"Style =" position: absolute; top :',
'', // Index 3, div top position
'Px; left :',
'', // Index 5, div left position
'Px; width :',
'', // Index 7, div width
'Px; Height :',
'', // Index 9, div height
'Px; overflow: hidden;/"> '', // Index 11, IMG URL
'/"Width = /"',
'', // Index 13, IMG width
'/"Height = /"',
'', // Index 15, IMG height
'/"Alt = /"',
'', // Index 17, IMG alt text
'/"> <// Div>'
];

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.