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 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

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.