复制代码 代码如下: //empty string is allowed as object property var o = {"":88, "p":99}; console.log(o);//Object { =88, p=99} //spaces can be included in property var o2 = {"good score":99, "bad score":52}; console.log(o2);//Object {good score=99, bad score=52}
值得注意的是,即使使用的字面量相同,每次使用字面量时,JavaScript都会创建一个全新的对象:
复制代码 代码如下: //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