Introduction to js literal volume, object literal volume access, and keyword in usage

Source: Internet
Author: User
Introduction to js literal volume, object literal volume access, and keyword in usage 1: literal meaning

A literal represents how this value is expressed. Generally, when a variable is assigned a value, the right side of the equal sign can be considered as a literal.

The literal is divided into string literal, array literal, and

Object literal and function literal ).

Example:

Var test = "hello world! ";
"Hello world! "Is the string literal, and test is the variable name.

2. Object literal volume

There are two access methods for object literal: Example,

Var obj = {
A: 'aaa', // a is an attribute, and 'aaa' is a property value.
B: 'bbb ',
C: 'ccc'
}

Method 1: When obj. a // aaa, for in traverses an object, this method is invalid...

Method 2: obj ['a'] // aaa, which must be enclosed by quotation marks

[The dot method is only applicable when the attribute is a string. If the attribute is a variable, only the latter can be used]

When the attribute is a variable, you can only assign values using the following method:


Var obj = {};
Obj [$ a] = 'value ';

If you write {$ a: 'value'} directly, $ a is parsed into a string.

Iii. keyword in usage

Format: (variable in object)... note ,,,

When "object" is an array, "variable" refers to the "Index" of the array ";

When "object" is an object, "variable" refers to the "attribute" of the object ".

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.