PDA

View Full Version : Object notation question.



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

Is there any difference between:


var object = {
name : "value"
};

and:


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

?

Thanks!

Nile
03-11-2009, 11:14 PM
Not from what I know. ;)

Twey
03-11-2009, 11:20 PM
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-11-2009, 11:24 PM
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.