PDA

View Full Version : Object notation question.


jlizarraga
03-11-2009, 11:41 PM
Hi all,

Is there any difference between:

var object = {
name : "value"
};

and:

var object = {
"name" : "value"
};

?

Thanks!

Nile
03-12-2009, 12:14 AM
Not from what I know. ;)

Twey
03-12-2009, 12:20 AM
No — but an unquoted name must be a valid identifier.


// These are equivalent:
({ foo: 5 });
({ 'foo' : 5 });

// But these are legal:
({ '1st' : 3 });
({ 'class' : 5 });
({ 'foo-bar' : 10 });
// While these are illegal:
({ 1st: 3 });
({ class: 5 });
({ foo-bar: 10 });

Master_script_maker
03-12-2009, 12:24 AM
Well the first is a more common practice, the second is more like defining array keys: var t=new Array("hi"=>5);, which is actually an object.