What is going on?


i have no idea how to do objects could someone please explain.
the codecademy guide didn't help


From MDN

An object is a collection of properties, and a property is an association between a name (or key) and a value. A property's value can be a function, in which case the property is known as a method. In addition to objects that are predefined in the browser, you can define your own objects.

From instruction:

There are two ways to create an object: using object literal notation (which is what you just did) and using the object constructor.

Literal notation:

var myObj = {
    type: 'fancy',
    disposition: 'sunny'

Constructor notation:
var myObj = new Object();

You can add keys to your object after you've created it in two ways:

myObj["name"] = "Charlie";
myObj.name = "Charlie";

More info (also you can to practice):
1. JavaScript Objects
2. JS Objects
3. MDN

If you need more answers you can always ask what you can't understand.


var me = new object();
me["name"] = "name"

this code should work but it doesnt?


var me = new object();

This doesn't work, if you are using constructor notation should be:

Constructor notation:
var myObj = new Object(); // you need to use uppercase


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