Talk about the literal quantity of JS, the access of object literal, the usage of keyword in _javascript skill

Source: Internet
Author: User

One: literal meaning

Literal means how to express this value, generally dropping an expression, and assigning a value to a variable, the right side of the equal sign can be considered literal.

The literal amount is divided into string literal quantities (string literal), array literal quantities (array literal), and

Object literal, and also a function literal (literal).

Example:

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

Two: Object literal quantity

There are two ways to access an object literal: the example below,

var obj = {
A: ' AAA ',//a is attribute, ' AAA ' is attribute value
B: ' BBB ',
C: ' CCC '
}

Method One: obj.a//aaa,for in Traversal object, this method is invalid ...

Method Two: obj[' A ']//aaa, must be quoted

"The point method only fits the case where the property is a string, and if the property is a variable, only the latter"

When a property is a variable, you can only assign values in the following ways:

var obj = {};
obj[$a] = ' value ';

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

Three: usage of keyword in

Format: (variable in object) ... Attention

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

When object is an object, variable refers to the object's properties.

The above article on the literal volume of JS, object literal access, keyword in the use of small parts to share all the content, I hope to give you a reference, but also hope that we support the cloud habitat community.

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.