Is there any difference between the following?:
var object1= {
a: 0,
b: 1,
c: 2
};
vs
var object2= {
'a': 0,
'b': 1,
'c': 2
};
There's no difference in your example. There would be a difference if you wanted your property names to be a number or have spaces (both of which are valid, but strange).
var object3 = {
'123': 0,
'hello world' : 1
}
// This is valid
alert(object3['123']); // -> 0
alert(object3['hello world']); // -> 1
// This is not
alert(object3.123); // -> Syntax Error
If you have two minutes you might find this page VERY helpful.
http://bonsaiden.github.com/JavaScript-Garden/#object.general
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With