1var obj = {
2 prop1: 5,
3 obj2: {
4 prop1: [3, 6, 3],
5 prop2: 74,
6 prop3: {
7 str: "Hello World"
8 }
9 }
10};
11
12console.log(obj.obj2.prop3.str); //output: "Hello World"
1function userCreator (name, score) {
2 const newUser = Object.create(userFunctionStore);
3 newUser.name = name;
4 newUser.score = score;
5 return newUser;
6};
7
8const userFunctionStore = {
9 increment: function() {
10 this.score++;
11 },
12
13 login: function() {
14 console.log("Logged in!");
15 }
16};
17
18const user1 = userCreator("Justin", 41);
19const user2 = userCreator("Rainer", 5);
20user1.increment();
21console.log(user1.score) // 42
1let myDog = {
2 legs: value
3
4}
5 console.log(myDog);
6/*Doesn't have to be a Dog it can be anyting you want*/
1// To make an object literal:
2const dog = {
3 name: "Rusty",
4 breed: "unknown",
5 isAlive: false,
6 age: 7
7}
8// All keys will be turned into strings!
9
10// To retrieve a value:
11dog.age; //7
12dog["age"]; //7
13
14//updating values
15dog.breed = "mutt";
16dog["age"] = 8;