Ambiguity of bracket "[]" in JavaScript

Source: Internet
Author: User
Tags valid

This article mainly introduces the ambiguity of the brackets "[]" in JavaScript. Need friends can come to the reference, I hope to help you

JavaScript brackets have four semantic semantics 1, declaring the array code as follows: var ary = []; Declares an empty array var ary = [1,3]; Declare an array, assign the initial value semantics 2, and take the array member code as follows: var ary = [1,2,3];   var item = ary[0];   Semantic 3, defines the object member (which can not follow the identifier rules) code as follows: var obj = {};    Adding a property to obj Name,name is a valid identifier, that is, you can also define obj[' name ' = ' Jack ' by Obj.name method;      Adding a property to obj 2a,2a is not a valid identifier (cannot begin with a number) and cannot be defined by obj.2a to define obj[' 2a ' = ' test '; Semantic 4, take the object member code as follows: var obj = {name: ' Jack '};   obj[' 2a '] = ' test '; obj[' name ']; --> Jack obj[' 2a ']; --> test (not available through obj.2a)
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.