Is there a difference between quoted and un-quoted JavaScript object property/method names?
For example, what is the difference between these two:
var obj1 = {
property1 : "Value 1",
method1 : function() {
return true;
}
};
var obj2 = {
"property1" : "Value 1",
"method1" : function() {
return true;
}
};
There is no difference in JavaScript. However you will have to quote property names that happen to be reserved words (such as
class), or names that contain invalid characters (such asfirst-name).