In JavaScript, you can create a new object directly by literal volume:
Copy Code code as follows:
var obj = {a:27, "B": 99};
As noted above, when you create an object in literal quantities, the property definition in the object can be included either in single or double quotes or by ignoring the quotation marks. However, when the property appears in spaces, slashes and other special characters, or use the property and JS keyword conflict, you must use quotation marks.
When you create an object in literal quantities, the property can be an empty string, and a space can appear in the property:
Copy Code code as follows:
Empty string is allowed as Object
var o = {"": the "P": 99};
Console.log (o);//object {=88, p=99}
Spaces can be included into property
var O2 = {"Good score": "," Bad Score ": 52};
Console.log (O2);//object {good score=99, bad score=52}
It's worth noting that, even if you use the same literal, JavaScript creates an entirely new object each time you use a literal:
Copy Code code as follows:
Every object literal creates a new and distinct object.
var x = {a:18, b:28};
var y = {a:18, b:28};
Console.log (x = = y);//false
In literal quantities, if the last comma ("}" character appears before ","), then some JavaScript interpreters will complain. In fact, in IE7, this behavior will cause the browser to suspend animation and other problems. In the ECMAScript 5 standard, "," appears before "," is legal, the comma will be directly ignored.