1. Does object literal === json type object?
2. Suppose there is a json type object, such as var a={};
3. What is the difference between operating json in the following ways:
①a.propertyA=valueA;
②var a={propertyA :valueA};
It is a way of defining attributes internally and externally
1. Does object literal === json type object?
2. Suppose there is a json type object, such as var a={};
3. What is the difference between operating json in the following ways:
①a.propertyA=valueA;
②var a={propertyA :valueA};
It is a way of defining attributes internally and externally
1. The object is a reference type, the === method is not true;
2. There is no difference between a.propertA=valueA and a={propertyA:valueA};. But please note that there is a difference if it is var a=function(){};a.prototype.propertyA=valueA and a.prototype={propertyA:valueA}.
There is no such thing as a JSON type object. var obj = {};
is called an object literal. JSON is the same syntax format as XML.
a={propertyA:valueA};
is to directly assign a value to a literal. a.propertyA=valueA
or a[propertyA]=valueA
can be used to access/modify/increase the attribute value of a literal. (When using the dot operator, propertyA must be a legal JavaScript identifier)
1. Object literal refers to using key/value to define objects. It is simple and clear. There is no limit on the value. The value of json
can only be: numbers (integers or floating point numbers), strings (in (in double quotes), logical value (true
or false
), array (in square brackets), object (in curly brackets), null
. In other words, the value of json
cannot be a function. So there is a difference between the two.
2, a.propertyA = valueA;
is equivalent to adding an attribute to the object, and the previously defined attributes still exist. And a = {propertyA: valueA};
overwrites a
, that is, the attributes in the previous a
have been overwritten. The a
object only has the attribute propertyA
.