17. Using Object Literal Notation vs. Object Construction


#1

I do not understand why my first attempt at creating an object using Object Literal Notation was correct yet when I attempted the same thing with Object Construction an error came up stating that I did not add any properties to myOwnObject.


var myOwnObject= {
    name:'zoe',
    age:23
};

//compare to

var myOwnObject= new Object();
name='zoe';
age=23;

Oops, try again. It looks like you didn't add any properties to myOwnObject!


#2

name and age are properties of myOwnObject so need to be written as identifierNames.

myOwnObject.name = "Zoe";
myOwnObject.age = 23;

#3

Thanks! I failed to notice that the different ways to make objects also included how to format the property names.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.