What is an object? Object naming and access rules, mainly numeric and special words such as key names

Source: Internet
Author: User

A fool's understanding, the object is wrapped in curly braces {} Things, the object has a key/value Key/value

In short, the JS object as long as it does not conform to the JS variable naming rules need to add quotation marks, both at the time of definition and reference, and the object can not be used as an array to use subscript access, can only use the Key Name key (property name) access

var obj = {' 1 ': 3, ' @**^%* ': ' I am the symbol oh ', 3:4, ' Tom Ni Hao ': 2}; Console.log (obj[1])//3, although there is no error in the new version of Chrome here, but because it does not conform to the JS variable name rules, so it is best to add a quotation mark, so Console.log (obj[' 1 ']) console.log (obj[' @**^%* ');//I am the symbol Oh console.log (obj[' 1 ']);//3Console.log (obj[3]);//4 Console.log (obj[' Tom Ni hao ');//2Console.log (obj.tom);//undefined

What is an object? Object naming and access rules, mainly numeric and special words such as key names

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.