为什么JS允许对象属性同时为"quoted"
和non-quoted
?有区别吗?
var object = {
"firstName": "SpongeBob", //quoted
lastName: "SquarePants" //non-quoted
};
console.log(object.firstName); // -> SpongeBob
console.log(object.lastName); // -> SquarePants
答案 0 :(得分:0)
当然有:
var obj = {
"crazy-property!name": "some string"
// crazy-property!name is an invalid property name without quotation marks
};
console.log(obj["crazy-property!name"]);
// can't do console.log(obj.crazy-property!name)