Skip to content

Commit 95eebb8

Browse files
committed
Object Basics
1 parent 6f1d95b commit 95eebb8

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

app.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,36 @@
1-
const heading = document.querySelector("h1");
2-
console.log(heading);
1+
// Objects Basics
2+
3+
/*
4+
Objects are collections of key (property) value pairs
5+
Property values can be strings, numbers, booleans, arrays and functions however if the property value is a function it's called a method
6+
*/
7+
8+
// object literal syntax,{}
9+
// dot notation
10+
11+
const person = {
12+
name: "john",
13+
age: 25,
14+
siblings: ["anna", "susan", "peter"],
15+
greet: function (name) {
16+
console.log(`Hi, I am ${name}`);
17+
},
18+
sayHello(name) {
19+
console.log(`Hello, My name is ${name}`);
20+
},
21+
};
22+
23+
console.log(person.name);
24+
25+
// aassign and access the variable
26+
const firstName = person.sayHello("john");
27+
28+
// Adding property
29+
person.city = "illinois";
30+
31+
//Deleting property
32+
// delete person.siblings;
33+
const deleteSiblings = delete person.siblings;
34+
console.log(deleteSiblings);
35+
36+
console.log(person);

0 commit comments

Comments
 (0)